#P4115. Qtree4
Qtree4
Description
You are given a tree with nodes, where each edge has a weight. Initially, all nodes are white. There are two types of operations:
C x: toggle the color of node ; white becomes black, and black becomes white.A: query the distance between the farthest two white nodes in the tree. These two white nodes may coincide (in which case the distance is ).
Input Format
The first line contains a positive integer ().
Each of the next lines contains three integers , , , representing an edge between nodes and with weight ().
The next line contains a positive integer (), the number of operations.
Each of the next lines contains one operation.
Output Format
For each A operation, if there are no white nodes in the tree, output a line with the string They have disappeared.. Otherwise, output a line with one integer, the distance between the farthest two white nodes in the tree.
3
1 2 1
1 3 1
7
A
C 1
A
C 2
A
C 3
A
2
2
0
They have disappeared.
Hint
Translated by ChatGPT 5
京公网安备 11011102002149号