Timer is Running

Even Distanced Tree Vertices[Duplicate] (Deleted)
##### Submissions: 220   Accuracy: 7.27%   Difficulty: Medium   Marks: 4

You have a tree consisting of N vertices. Print the number of Pairs of nodes that are at an even distance.

Input:
The First line contains an integer T, the number of testcases.
The first line of each testcase contains an integer N , the total number of vertices.
The second line contains 2*(N-1) space-separated vertices (u and v) connecting nodes in the tree.

Output:
Print the total number of pairs having even distance between them.

Constraints:
1<=T<=10
1<= N <=10000
1<= u, v <=N

Example:
Input:

1
5
1 3 1 2 2 4 3 5

Output:
4

Explanation:

There are  pairs with even distance between them:
(2,3) distance=2
(4,5) distance=4
(4,1) distacne=2
(1,5) distance=2

#### ** For More Input/Output Examples Use 'Expected Output' option **

Contributor: Abhinav Jain(iamabjain)
Author: iamabjain

If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.

Need help with your code? Please use ide.geeksforgeeks.org, generate link and share the link here.

to report an issue on this page.