#P10776. BZOJ3914 Jabby's shadows
BZOJ3914 Jabby's shadows
Problem Description
You are given an unrooted tree with nodes. The tree edges have weights. Each node has one of two colors. Initially, all nodes are black. Black is , and white is . Each edge has a positive weight.
You need to maintain operations:
1 u: Query the diameter of the monochromatic connected component (connected block with the same color) that contains node . If it is , outputQwQ.2 u v c: Recolor (cover) the path from to with color .
Input Format
The first line contains a positive integer , the number of nodes in the tree.
The second line contains positive integers , the parent of nodes .
The third line contains positive integers , the edge weight of the edge from node to its parent.
The fourth line contains a positive integer , the number of operations. The next lines describe the operations in order.
Output Format
For each operation of type , output one line as the answer.
5
1 2 3 3
2 2 4 3
5
1 3
1 1
2 4 4 2
2 3 1 1
1 2
8
8
7
Hint
Constraints: , .
Translated by ChatGPT 5