#P10866. [HBCPC2024] Colorful Tree
[HBCPC2024] Colorful Tree
题目描述
You are given a tree with nodes numbered from to and edges. Each node has a color. Initially, all of them are white.
We are going to perform operations. In each operation, two vertices and will be given, and we will color black to the points along the simple path from to ( inclusive). Note that a simple path in the tree is defined as a path that does not pass through any vertex more than once.
After each operation, you are required to determine the length of the longest simple path in the tree where all nodes on the path are the same color. The length of a path is defined as the number of nodes on the path.
输入格式
The first line contains a single integer () indicating the number of test cases.
For each test case, the first line contains two integers () and (), indicating the number of nodes in the tree and the number of operations, respectively.
In the following lines, each contains two integers and , representing an edge from vertex to in the tree.
Then follow lines, each contains two integers and , representing an operation that colors black to the points along the path from vertex to .
It is guaranteed that the sum of and of all the test cases in a test does not exceed respectively.
输出格式
For each test case, output lines, each line should contain an integer representing the length of the longest simple path in the tree where all nodes on the path are the same color after the corresponding operation.
1
8 6
1 2
1 3
2 4
4 5
2 6
4 8
3 7
4 8
7 7
4 5
2 2
4 6
5 1
5
4
4
3
4
4