using
System;
using
System.Collections.Generic;
class
GFG
{
static
void
dfs(List<
int
> []graph,
int
node,
int
[]dist,
bool
[]vis,
int
c)
{
if
(vis[node])
{
return
;
}
vis[node] =
true
;
dist[node] = c;
for
(
int
i = 0; i < graph[node].Count; i++)
{
if
(!vis[graph[node][i]])
{
dfs(graph, graph[node][i],
dist, vis, c + 1);
}
}
}
static
int
countOfNodes(List<
int
> []graph,
int
n)
{
bool
[]vis =
new
bool
[n + 1];
int
[]dist =
new
int
[n + 1];
dfs(graph, 1, dist, vis, 0);
int
even = 0, odd = 0;
for
(
int
i = 1; i <= n; i++)
{
if
(dist[i] % 2 == 0)
{
even++;
}
else
{
odd++;
}
}
int
ans = ((even * (even - 1)) +
(odd * (odd - 1))) / 2;
return
ans;
}
public
static
void
Main(String[] args)
{
int
n = 5;
List<
int
> []graph =
new
List<
int
>[n + 1];
for
(
int
i = 0; i< n + 1; i++)
{
graph[i] =
new
List<
int
>();
}
graph[0] =
new
List<
int
>{};
graph[1] =
new
List<
int
>{2};
graph[2] =
new
List<
int
>{1, 3};
graph[3] =
new
List<
int
>{2};
int
ans = countOfNodes(graph, n);
Console.WriteLine(ans);
}
}