#P15761. [JAG 2025 Summer Camp #1] Colored Tree and Path
[JAG 2025 Summer Camp #1] Colored Tree and Path
题目描述
You are given a tree with vertices, numbered through . Edge connects vertices and . Each vertex is assigned a color .
You are asked to process queries. In each query, four integers are given.
For each query, determine the maximum integer () such that the following condition holds:
- For every , the number of vertices of color on the path from to is equal to the number of vertices of color on the path from to .
输入格式
The input is given in the following format:
$$\begin{aligned} & N \\ & a_1 \ b_1 \\ & a_2 \ b_2 \\ & \vdots \\ & a_{N-1} \ b_{N-1} \\ & c_1 \ c_2 \ \ldots \ c_N \\ & Q \\ & \text{Query}_1 \\ & \text{Query}_2 \\ & \vdots \\ & \text{Query}_Q \end{aligned}$$Each Query is given in the following format:
- ()
- ()
- ()
- The given graph is a tree.
- All input values are integers.
输出格式
Output lines. On the -th line (), output the answer for the -th query.
6
2 3
4 3
6 2
3 5
2 1
1 2 2 3 1 1
4
1 6 5 4
6 5 1 5
1 1 6 6
1 5 4 2
0
6
6
0