4898 - 树形动态:树的重心(质心)

Consider a tree T with N (1 <= N <= 20,000) nodes numbered 1...N. Deleting any node from the tree yields a forest: a collection of one or more trees. Define the balance of a node to be the size of the largest tree in the forest T created by deleting that node from T. For example, consider the tree: 大致意思: 给定一棵树,求树的重心的编号以及重心删除后得到的最大子树的节点个数size,如果size相同就选取编号最小的

输入

The first line of input contains a single integer t (1 <= t <= 20), the number of test cases. The first line of each test case contains an integer N (1 <= N <= 20,000), the number of congruence. The next N-1 lines each contains two space-separated node numbers that are the endpoints of an edge in the tree. No edge will be listed twice, and all edges will be listed.

输出

For each test case, print a line containing two integers, the number of the node with minimum balance and the balance of that node.

样例

输入

1
7
2 6
1 2
1 4
4 5
3 7
3 1

输出

1 2
时间限制 1 秒
内存限制 64 MB
讨论 统计
上一题 下一题