CF1238F.The Maximum Subtree
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Assume that you have k one-dimensional segments s1,s2,…sk (each segment is denoted by two integers — its endpoints). Then you can build the following graph on these segments. The graph consists of k vertexes, and there is an edge between the i -th and the j -th vertexes ( i=j ) if and only if the segments si and sj intersect (there exists at least one point that belongs to both of them).
For example, if s1=[1,6],s2=[8,20],s3=[4,10],s4=[2,13],s5=[17,18] , then the resulting graph is the following:
A tree of size m is good if it is possible to choose m one-dimensional segments so that the graph built on these segments coincides with this tree.
You are given a tree, you have to find its good subtree with maximum possible size. Recall that a subtree is a connected subgraph of a tree.
Note that you have to answer q independent queries.
输入格式
The first line contains one integer q ( 1≤q≤15⋅104 ) — the number of the queries.
The first line of each query contains one integer n ( 2≤n≤3⋅105 ) — the number of vertices in the tree.
Each of the next n−1 lines contains two integers x and y ( 1≤x,y≤n ) denoting an edge between vertices x and y . It is guaranteed that the given graph is a tree.
It is guaranteed that the sum of all n does not exceed 3⋅105 .
输出格式
For each query print one integer — the maximum size of a good subtree of the given tree.
输入输出样例
输入#1
1 10 1 2 1 3 1 4 2 5 2 6 3 7 3 8 4 9 4 10
输出#1
8
说明/提示
In the first query there is a good subtree of size 8 . The vertices belonging to this subtree are 9,4,10,2,5,1,6,3 .