#abc302e. E - Isolation

E - Isolation

Score : 425425 points

问题描述

存在一个含 NN 个顶点的无向图,顶点编号为从 11NN,且最初有 00 条边。
给定 QQ 个查询,按照顺序处理它们。在处理完每个查询后,输出未通过边与其他任何顶点相连的顶点数目。

ii 个查询 queryi\mathrm{query}_i 属于以下两种类型之一。

  • 1 u v: 连接顶点 uu 和顶点 vv 之间的边。保证在给出此查询时,顶点 uu 和顶点 vv 之间没有边相连。

  • 2 v: 删除所有连接顶点 vv 与其他顶点的边。(顶点 vv 本身不会被移除。)

以上为通义千问 qwen-max 翻译,仅供参考。

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.

Sample Input 1

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

Sample Output 1

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.

Sample Input 2

2 1
2 1

Sample Output 2

2

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

update @ 2024/3/10 08:29:45