The Maximum Subtree
题意翻译
#### 题目描述
定义一个大小为 $n$ 的树是好的,为存在一种给每一个节点 $i$ 赋两个值 $l_i,r_i$ 分别代表线段的左端点和右端点的方案,使得两个点 $u,v$ 在树上有边当且仅当 $u,v$ 所代表的线段有交集。
现在给定一棵大小为 $n$ 的树,让你求出最大的好的子树的大小。多组数据。
本题中“子树”指树上的一个连通子图。
#### 输入格式
第一行一个正整数表示数据组数 $q$ $(1\le q\le 1.5\times 10^5)$。
接下来 $q$ 组数据,每组询问第一行一个整数 $n$ $(2\le n\le 3\times 10^5)$ 代表树的节点数,后面 $n-1$ 行每行两个数 $u,v$ 代表树上的一条边 $(u,v)$。
数据保证 $\sum n\le 3\times 10^5$。
#### 输出格式
对于每组数据,输出最大的好的子树的大小。
题目描述
Assume that you have $ k $ one-dimensional segments $ s_1, s_2, \dots s_k $ (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 \neq j $ ) if and only if the segments $ s_i $ and $ s_j $ intersect (there exists at least one point that belongs to both of them).
For example, if $ s_1 = [1, 6], s_2 = [8, 20], s_3 = [4, 10], s_4 = [2, 13], s_5 = [17, 18] $ , then the resulting graph is the following:
![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF1238F/5ccebeabf5d6a202b692741f0fad2573638b500c.png)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 \le q \le 15 \cdot 10^4 $ ) — the number of the queries.
The first line of each query contains one integer $ n $ ( $ 2 \le n \le 3 \cdot 10^5 $ ) — the number of vertices in the tree.
Each of the next $ n - 1 $ lines contains two integers $ x $ and $ y $ ( $ 1 \le x, y \le 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 \cdot 10^5 $ .
输出格式
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} $ .