Tree Paths

아직 제출이 없습니다시간 제한7초메모리 제한512 MB

문제

There is a tree of NN vertices numbered 11 to NN. A path is a sequence of distinct vertices (v_1,,v_k)(v\_1, \ldots, v\_k) such that k1k \geq 1, v_iv_i+1v\_i v\_{i+1} is an edge for all 1ik11 \leq i \leq k-1, and v_1v_kv\_1 \leq v\_k.

Count the number of paths such that the vertices v_1,,v_kv\_1, \ldots, v\_k form a contiguous range, or more formally, the set v_1,,v_k=a,a+1,,b\\{v\_1, \ldots, v\_k\\} = \\{a, a+1, \ldots, b\\} for some integers aba \leq b.

입력

The first line contains an integer NN (1N50,0001 \leq N \leq 50\\,000). The next N1N-1 lines contain the edges of the tree. The ii-th of these lines contains two space-separated integers u_iu\_i and v_iv\_i (1u_i,v_iN1 \leq u\_i, v\_i \leq N) denoting that u_iv_iu\_i v\_i is an edge. It is guaranteed that the given graph is a tree.

출력

On a single line output the desired number of paths.

힌트

The paths are (1)(1), (2)(2), (3)(3), (1,2)(1,2), and (2,1,3)(2,1,3).