#icpc2016autumne. [icpc2016autumn_e]Similarity of Subtrees

[icpc2016autumn_e]Similarity of Subtrees

MathJax.Hub.Config({ tex2jax: { inlineMath: [["","",""], ["\\(","\\)"]], processEscapes: true }}); blockquote { font-family: Menlo, Monaco, "Courier New", monospace; color: #333333; display: block; padding: 8.5px; margin: 0 0 9px; font-size: 12px; line-height: 18px; background-color: #f5f5f5; border: 1px solid #ccc; border: 1px solid rgba(0, 0, 0, 0.15); -webkit-border-radius: 4px; -moz-border-radius: 4px; border-radius: 4px; white-space: pre; white-space: pre-wrap; word-break: break-all; word-wrap: break-word; }

Problem Statement

Define the depth of a node in a rooted tree by applying the following rules recursively:

  • The depth of a root node is 0.
  • The depths of child nodes whose parents are with depth dd are d+1d+1.

Let S(T,d)S(T, d) be the number of nodes of TT with depth dd. Two rooted trees TT and TT' are similar if and only if S(T,d)S(T, d) equals S(T,d)S(T', d) for all non-negative integer dd.

You are given a rooted tree TT with NN nodes. The nodes of TT are numbered from 1 to NN. Node 1 is the root node of TT. Let T_iT\_i be the rooted subtree of TT whose root is node ii. Your task is to write a program which calculates the number of pairs (i,j)(i, j) such that T_iT\_i and T_jT\_j are similar and i<ji < j.


Input

The input consists of a single test case.

NN
a_1a\_1 b_1b\_1

a_N1a\_{N-1} b_N1b\_{N-1}

The first line contains an integer NN (1leNle100,0001 \\le N \\le 100{,}000), which is the number of nodes in a tree. The following N1N-1 lines give information of branches: the ii-th line of them contains a_ia\_i and b_ib\_i, which indicates that a node a_ia\_i is a parent of a node b_ib\_i. (1lea_i,b_ileN1 \\le a\_i, b\_i \\le N, a_ineb_ia\_i \\ne b\_i) The root node is numbered by 1. It is guaranteed that a given graph is a rooted tree, i.e. there is exactly one parent for each node except the node 1, and the graph is connected.

Output

Print the number of the pairs (x,y)(x,y) of the nodes such that the subtree with the root xx and the subtree with the root yy are similar and x<yx < y.



Sample Input 1

5
1 2
1 3
1 4
1 5```

### Output for the Sample Input 1

```plain
6```

* * *

### Sample Input 2

```plain
6
1 2
2 3
3 4
1 5
5 6```

### Output for the Sample Input 2

```plain
2```

* * *

### Sample Input 3

```plain
13
1 2
1 3
2 4
2 5
3 6
3 7
4 8
4 9
6 10
7 11
8 12
11 13```

### Output for the Sample Input 3

```plain
14```

* * *