#P10866. [HBCPC2024] Colorful Tree

[HBCPC2024] Colorful Tree

题目描述

You are given a tree with nn nodes numbered from 11 to nn and n1n - 1 edges. Each node has a color. Initially, all of them are white.

We are going to perform qq operations. In each operation, two vertices uu and vv will be given, and we will color black to the points along the simple path from uu to vv (u,vu,v 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 TT (1T1001 \le T \le 100) indicating the number of test cases.

For each test case, the first line contains two integers nn (1n2×1051 \le n \le 2\times 10^5) and qq (1q2×1051 \le q \le 2\times 10^5), indicating the number of nodes in the tree and the number of operations, respectively.

In the following n1n-1 lines, each contains two integers uu and vv, representing an edge from vertex uu to vv in the tree.

Then follow qq lines, each contains two integers uu and vv, representing an operation that colors black to the points along the path from vertex uu to vv.

It is guaranteed that the sum of nn and qq of all the test cases in a test does not exceed 2×1052\times 10^5 respectively.

输出格式

For each test case, output qq 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