P10866 [HBCPC2024] Colorful Tree
Description
You are given a tree with $n$ nodes numbered from $1$ to $n$ and $n - 1$ edges. Each node has a color. Initially, all of them are white.
We are going to perform $q$ operations. In each operation, two vertices $u$ and $v$ will be given, and we will color black to the points along the simple path from $u$ to $v$ ($u,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.
Input Format
The first line contains a single integer $T$ ($1 \le T \le 100$) indicating the number of test cases.
For each test case, the first line contains two integers $n$ ($1 \le n \le 2\times 10^5$) and $q$ ($1 \le q \le 2\times 10^5$), indicating the number of nodes in the tree and the number of operations, respectively.
In the following $n-1$ lines, each contains two integers $u$ and $v$, representing an edge from vertex $u$ to $v$ in the tree.
Then follow $q$ lines, each contains two integers $u$ and $v$, representing an operation that colors black to the points along the path from vertex $u$ to $v$.
It is guaranteed that the sum of $n$ and $q$ of all the test cases in a test does not exceed $2\times 10^5$ respectively.
Output Format
For each test case, output $q$ 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.