10307: CF EDU - DSU - Step 2 - I. Bipartite Graph
[Creator : ]
Description
You are given an empty undirected graph on $n$ vertices. Each vertex is colored in one of two colors $0$ or $1$ at any moment in time, such that each edge connects the vertices with different colors.
There are two types of queries:
- You are given two vertices $x$ and $y$ from different connected components: add an edge $(x,y)$ to the graph, and change the colors to satisfy the condition.
- You are given two vertices $x$ and $y$ from one connected component: answer whether they are of the same color.
Initially the graph is empty.
Input
The first line contains two integers $n,m\ (1≤n,m≤2⋅10^5)$ — the number of vertices in the graph and the number of queries, respectively. The vertices are indexed starting from zero.
Next $m$ lines contain the queries.
- The query of the first type has the following form: "0 a b" $(1≤a,b≤n)$, meaning that you have to unite two components with vertices $x$ and $y$, such that $x \bmod {n}=(a+shift)\bmod n$ and $y\bmod n=(b+shift)\bmod n$
-
The query of the second type has the following form: "1 a b" $(1≤a,b≤n)$, meaning that you have to check the difference of colors of vertices $x$ and $y$, such that $x\bmod n=(a+shift)\bmod n$ and $y\bmod n=(b+shift)\bmod n$
If the answer on the query is positive, then you have to set $shift=(shift+1)\bmod n$.
Initially, shift is equal to zero.
Output
For each query of the second type output "YES", if the colors are the same, otherwise, output "NO", on a separate line.
Sample 1 Input
3 5
0 1 2
0 2 3
1 1 2
1 1 3
1 1 3
Sample 1 Output
NO
YES
NO