/
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 800 点
問題文
N 頂点 M 辺の連結な単純無向グラフが与えられます。頂点には 1 から N までの番号が付いており、i 番目の辺は頂点 u_i と頂点 v_i を結んでいます。
各頂点は白または黒に塗られています。初期状態は長さ N の文字列 S で表され、S_i が 0 のとき頂点 i は白、1 のとき黒です。
以下の操作を好きな回数(0 回でもよい)行ってすべての頂点を白にできる状態を、良い状態 と呼びます。
- 相異なる 3 頂点 a,b,c であって、a と b、b と c がそれぞれ辺で結ばれているものを選び、これら 3 頂点の色をそれぞれ反転する。すなわち、白なら黒に、黒なら白にする。
なお、頂点 a と頂点 c が辺で結ばれていても構いません。
Q 個のクエリを順に処理してください。i 番目のクエリは以下の通りです。
- 整数 x_i が与えられる。頂点 x_i の色を反転する。その後、グラフが良い状態にあるかを判定する。
クエリによる色の変更は、以降のクエリにも引き継がれます。
制約
- 3 \le N \le 2 \times 10^5
- N-1 \le M \le 2 \times 10^5
- 1 \le Q \le 2 \times 10^5
- S は
0,1からなる長さ N の文字列 - 1 \le u_i,v_i \le N
- 1 \le x_i \le N
- 与えられるグラフは連結な単純無向グラフ
- 入力される数値はすべて整数
入力
入力は以下の形式で標準入力から与えられます。
N M Q S u_1 v_1 u_2 v_2 \vdots u_M v_M x_1 x_2 \vdots x_Q
出力
Q 行出力してください。i 行目には、i 番目のクエリを処理した後の状態が良ければ Yes、そうでなければ No を出力してください。
入力例 1
3 3 5 100 1 2 2 3 3 1 1 1 2 3 2
出力例 1
Yes No No Yes No
各クエリを処理した直後の色を文字列で表すと、順に 000、100、110、111、101 です。
このグラフではどの操作でも 3 頂点すべての色が反転するため、色がそろっている 1 番目と 4 番目のクエリの答えが Yes です。
入力例 2
4 3 4 1000 1 2 2 3 3 4 4 2 3 4
出力例 2
Yes No No Yes
1 番目のクエリで頂点 4 の色を反転すると 1001 になります。
(a,b,c)=(1,2,3),(2,3,4) の順に操作すると 0111 を経て 0000 になるため、答えは Yes です。
2 番目のクエリでは 1001 から頂点 2 の色を反転するので、状態は 1101 になります。
Score : 800 points
Problem Statement
You are given a connected simple undirected graph with N vertices and M edges. The vertices are numbered from 1 to N, and the i-th edge connects vertices u_i and v_i.
Each vertex is painted white or black. The initial state is represented by a string S of length N: vertex i is white if S_i is 0, and black if it is 1.
A coloring is good if all vertices can be made white by performing the following operation any number of times, possibly zero.
- Choose three distinct vertices a,b,c such that a and b are connected by an edge and b and c are connected by an edge, and flip the color of each of these three vertices. That is, a white vertex becomes black, and a black vertex becomes white.
Here, vertices a and c may also be connected by an edge.
Process Q queries in the given order. The i-th query is as follows.
- Given an integer x_i, flip the color of vertex x_i. Then, determine whether the resulting coloring is good.
The color change in each query carries over to subsequent queries.
Constraints
- 3 \le N \le 2 \times 10^5
- N-1 \le M \le 2 \times 10^5
- 1 \le Q \le 2 \times 10^5
- S is a string of length N consisting of
0and1. - 1 \le u_i,v_i \le N
- 1 \le x_i \le N
- The given graph is a connected simple undirected graph.
- All input numbers are integers.
Input
The input is given from Standard Input in the following format:
N M Q S u_1 v_1 u_2 v_2 \vdots u_M v_M x_1 x_2 \vdots x_Q
Output
Output Q lines. On the i-th line, print Yes if the coloring after processing the i-th query is good, and No otherwise.
Sample Input 1
3 3 5 100 1 2 2 3 3 1 1 1 2 3 2
Sample Output 1
Yes No No Yes No
The colorings immediately after each query are 000, 100, 110, 111, and 101, in that order.
Every operation on this graph flips all three vertices, so the coloring is good exactly when all three vertices have the same color. The answers to the first and fourth queries are therefore Yes.
Sample Input 2
4 3 4 1000 1 2 2 3 3 4 4 2 3 4
Sample Output 2
Yes No No Yes
Flipping the color of vertex 4 in the first query gives 1001.
Performing the operations with (a,b,c)=(1,2,3),(2,3,4) in this order gives 0111 and then 0000, so the answer is Yes.
The second query starts from 1001 and flips the color of vertex 2, giving 1101.