#P4116. Qtree3

    ID: 3050 远端评测题 1000ms 125MiB 尝试: 0 已通过: 0 难度: 7 上传者: 标签>线段树O2优化枚举,暴力树链剖分,树剖块状链表,块状数组,分块

Qtree3

Description

Given a tree with NN nodes (N1N-1 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 11 to vv; if none, output -1.

Input Format

The first line contains NN and QQ, the number of nodes and the number of operations.

Lines 22 through NN contain the N1N-1 undirected edges.

Then QQ 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 1/31/3 of the testdata, N=5000,Q=400000N=5000,Q=400000.

For 1/31/3 of the testdata, N=10000,Q=300000N=10000,Q=300000.

For 1/31/3 of the testdata, N=100000,Q=100000N=100000, Q=100000.

In addition, 1i,vN1 \le i,v \le N.

Translated by ChatGPT 5