#P4116. Qtree3
Qtree3
Description
Given a tree with nodes ( edges). Each node is either white or black, and initially all nodes are white.
There are two operations:
0 i: Toggle the color of a node (black becomes white, white becomes black).
1 v: Query the first black node on the path from to ; if none, output -1.
Input Format
The first line contains and , the number of nodes and the number of operations.
Lines through contain the undirected edges.
Then lines follow, each containing one operation 0 i or 1 v.
Output Format
For each 1 v operation, output the result.
9 8
1 2
1 3
2 4
2 9
5 9
7 9
8 9
6 8
1 3
0 8
1 6
1 7
0 2
1 9
0 2
1 9
-1
8
-1
2
-1
Hint
For of the testdata, .
For of the testdata, .
For of the testdata, .
In addition, .
Translated by ChatGPT 5
京公网安备 11011102002149号