atcoder#ABC302E. [ABC302E] Isolation

[ABC302E] Isolation

Score : 425425 points

Problem Statement

There is an undirected graph with NN vertices numbered 11 through NN, and initially with 00 edges. Given QQ queries, process them in order. After processing each query, print the number of vertices that are not connected to any other vertices by an edge.

The ii-th query, queryi\mathrm{query}_i, is of one of the following two kinds.

  • 1 u v: connect vertex uu and vertex vv with an edge. It is guaranteed that, when this query is given, vertex uu and vertex vv are not connected by an edge.
  • 2 v: remove all edges that connect vertex vv and the other vertices. (Vertex vv itself is not removed.)

Constraints

  • 2N3×1052 \leq N\leq 3\times 10^5
  • 1Q3×1051 \leq Q\leq 3\times 10^5
  • For each query of the first kind, 1u,vN1\leq u,v\leq N and uvu\neq v.
  • For each query of the second kind, 1vN1\leq v\leq N.
  • Right before a query of the first kind is given, there is no edge between vertices uu and vv.
  • All values in the input are integers.

Input

The input is given from Standard Input in the following format:

NN QQ

query1\mathrm{query}_1

query2\mathrm{query}_2

\vdots

queryQ\mathrm{query}_Q

Output

Print QQ lines. The ii-th line (1iQ)(1\leq i\leq Q) should contain the number of vertices that are not connected to any other vertices by an edge.

3 7
1 1 2
1 1 3
1 2 3
2 1
1 1 2
2 2
1 1 2
1
0
0
1
0
3
1

After the first query, vertex 11 and vertex 22 are connected to each other by an edge, but vertex 33 is not connected to any other vertices. Thus, 11 should be printed in the first line.

After the third query, all pairs of different vertices are connected by an edge. However, the fourth query asks to remove all edges that connect vertex 11 and the other vertices, specifically to remove the edge between vertex 11 and vertex 22, and another between vertex 11 and vertex 33. As a result, vertex 22 and vertex 33 are connected to each other, while vertex 11 is not connected to any other vertices by an edge. Thus, 00 and 11 should be printed in the third and fourth lines, respectively.

2 1
2 1
2

When the query of the second kind is given, there may be no edge that connects that vertex and the other vertices.