A silent Voice!

0

0 votes
Problem

Considering a parallel universe, Shouko never meets Ishida in high school. Since Ishida has shut everyone from his life after incident with Shouka, now he wants to be friend with her again.

Ishida hurries home and creates a tree where he places himself at root node marked as 1. He builds the tree so that he can reach Shouka Nishimiya. All other nodes are his friends from middle school some of them being Kawai, Yuzuru, Sahara, Ueno and others. There is always a unique path between any two friends(nodes). 

Ishida being curious defines a parameter D(i,j) as number of edges in the unique path between friend i and j.  

He asks you to find number of pairs of friends (i,j) such that D(i,j) = D(i,1) - D(j,1). 

Input:

The first line contains N denoting the number of edges in the tree Ishida formed. Next N−1 lines denote the edges of the tree.

Output:

Print a single integer denoting the number of pairs (i, j) such that and D(i,j)=D(i,1)−D(j,1).

Constraints:

1≤N≤105

Time Limit: 5
Memory Limit: 256
Source Limit:
Explanation

All pairs follow the given condition: (1, 1), (1, 2), (1, 3), (1, 4), (2, 2), (2, 3), (2, 4), (3, 3), (3, 4), (4, 4).

Editor Image

?