시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
---|---|---|---|---|---|
2 초 (추가 시간 없음) | 512 MB | 7 | 6 | 6 | 85.714% |
New meta.
A zigzag cycle in an undirected graph is a sequence of vertices $a_0, a_1, \ldots, a_{k-1}$, \uline{not necessarily distinct}, such that for all $i: 0 \leq i < k$ $a_i$ and $a_{(i+1) \mod k}$ are adjacent in the graph and one of the following holds:
A cycle contains the edge $(u, v)$ $p$ times if there exist exactly $p$ distinct $i: 0 \leq i < k$, such that $a_i = u, a_{(i+1) \mod k} = v$ or $a_i = v, a_{(i+1) \mod k} = u$.
A graph is splittable if there exists a set of zigzag cycles, such that for each edge exactly one cycle contains it $1$ time and all the remaining cycles contain it $0$ times, i.e. you can split edges of the graph into zigzag cycles.
There is a graph which is initially empty. Process the following types of queries:
After each query print whether the graph is splittable.
The first line contains two integers $n$ and $q$ ($2 \leq n \leq 3 \cdot 10^5, 1 \leq q \leq 3 \cdot 10^5$) --- the number of vertices in the graph and the number of queries, respectively.
$q$ lines follow. $i$-th of them contains three integers $t, u, v$ ($t \in \{1, 2\}, 1 \leq u < v \leq n$) --- the type of query and the endpoints of the edge you have to add if $t = 1$ or remove if $t = 2$. No query will ask to you to add an already present edge or to delete an absent one.
Print $q$ lines. $i$-th of them should contain 1
if the graph is splittable after the first $i$ queries and 0
otherwise.
6 10 1 1 4 1 1 5 1 4 5 1 3 5 1 3 4 2 4 5 1 4 5 1 2 5 1 2 6 1 4 6
0 0 0 0 0 1 0 0 0 1
After processing all the queries one possible set of zigzag cycles is $\{[1,4,3,5], [2,6,4,5]\}$.