You are given a tree. Simple path of length m is a sequence of vertices v1,v2,…,vm such that
For each vertex find length of longest simple path that goes through this vertex. Also count number of this paths. Two paths considered distinct if set of vertices of this paths differ.
Input Format:
First line of input contains single positive integer n -- number of vertices of the tree.
Next n−1 lines contains pairs space-separated integers ui,vi -- edges of the tree.
Output Format:
Output n lines. i-th line must contain two integers -- length of the longest simple path containing vertex i and number of such paths.
Constraints:
1⩽n⩽300,000.
Scoring:
50 points
Additionally n⩽3,000.
50 points
No additional constraints.
Longest paths going through vertex 1: (1,2,3), (1,2,4).
Longest paths going through vertex 2: (1,2,3), (1,2,4), (3,2,4).
Cases of vertices 3 and 4 are similar to vertex 1.