Codeforces Round 947 (Div. 1 + Div. 2)
E
Chain Queries
Codeforces
2100
原题
← DF →
翻译中…

You are given a tree of $n$ vertices numbered from $1$ to $n$. Initially, all vertices are colored white or black.

翻译中…

You are asked to perform $q$ queries:

翻译中…
  • "u" — toggle the color of vertex $u$ (if it was white, change it to black and vice versa).
翻译中…

After each query, you should answer whether all the black vertices form a chain. That is, there exist two black vertices such that the simple path between them passes through all the black vertices and only the black vertices. Specifically, if there is only one black vertex, they form a chain. If there are no black vertices, they do not form a chain.

翻译中…

Input

翻译中…

Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1\leq t\leq 10^4$). The description of the test cases follows.

翻译中…

The first line of each test case contains two integers $n$ and $q$ ($1\leq n,q\leq 2\cdot 10^5$).

翻译中…

The second line of each test case contains $n$ integers $c_1,c_2,\ldots,c_n$ ($c_i \in \{ \mathtt{0}, \mathtt{1} \}$) — the initial color of the vertices. $c_i$ denotes the color of vertex $i$ where $\mathtt{0}$ denotes the color white, and $\mathtt{1}$ denotes the color black.

翻译中…

Then $n - 1$ lines follow, each line contains two integers $x_i$ and $y_i$ ($1 \le x_i,y_i \le n$), indicating an edge between vertices $x_i$ and $y_i$. It is guaranteed that these edges form a tree.

翻译中…

The following $q$ lines each contain an integer $u_i$ ($1 \le u_i \le n$), indicating the color of vertex $u_i$ needs to be toggled.

翻译中…

It is guaranteed that the sum of $n$ and $q$ over all test cases respectively does not exceed $2\cdot 10^5$.

翻译中…

Output

翻译中…

For each query, output "Yes" if the black vertices form a chain, and output "No" otherwise.

翻译中…

You can output "Yes" and "No" in any case (for example, strings "yEs", "yes", "Yes" and "YES" will be recognized as a positive response).

翻译中…

Note

翻译中…

In the second test case, the color of the vertices are as follows:

翻译中…

The initial tree:

翻译中…

image

翻译中…

The first query toggles the color of vertex $4$:

翻译中…

image

翻译中…

The second query toggles the color of vertex $3$:

翻译中…

image

翻译中…

The third query toggles the color of vertex $2$:

翻译中…

image

翻译中…

The fourth query toggles the color of vertex $5$:

翻译中…

image

翻译中…

样例

Input #1
2
2 1
1 0
1 2
1
5 4
1 0 0 0 0
1 2
1 3
1 5
3 4
4
3
2
5
Output #1
No
No
Yes
Yes
No
InputCopy OutputCopy
Input #2
4
5 3
1 1 1 1 1
3 5
2 5
3 4
1 5
1
1
1
4 4
0 0 0 0
1 2
2 3
1 4
1
2
3
2
1 1
1
1
1 1
0
1
Output #2
Yes
No
Yes
Yes
Yes
Yes
No
No
Yes
InputCopy OutputCopy
题目信息
题号
1975E
时间限制
2 s
内存限制
256 MB
标签
二分
数据结构
DFS 及类似
模拟
树

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。