#abc302e. E - Isolation
E - Isolation
Score : points
问题描述
存在一个含 个顶点的无向图,顶点编号为从 到 ,且最初有 条边。
给定 个查询,按照顺序处理它们。在处理完每个查询后,输出未通过边与其他任何顶点相连的顶点数目。
第 个查询 属于以下两种类型之一。
-
1 u v
: 连接顶点 和顶点 之间的边。保证在给出此查询时,顶点 和顶点 之间没有边相连。 -
2 v
: 删除所有连接顶点 与其他顶点的边。(顶点 本身不会被移除。)
以上为通义千问 qwen-max 翻译,仅供参考。
Problem Statement
There is an undirected graph with vertices numbered through , and initially with edges.
Given 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 -th query, , is of one of the following two kinds.
-
1 u v
: connect vertex and vertex with an edge. It is guaranteed that, when this query is given, vertex and vertex are not connected by an edge. -
2 v
: remove all edges that connect vertex and the other vertices. (Vertex itself is not removed.)
Constraints
- For each query of the first kind, and .
- For each query of the second kind, .
- Right before a query of the first kind is given, there is no edge between vertices and .
- All values in the input are integers.
Input
The input is given from Standard Input in the following format:
Output
Print lines.
The -th line 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 and vertex are connected to each other by an edge, but vertex is not connected to any other vertices.
Thus, 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 and the other vertices, specifically to remove the edge between vertex and vertex , and another between vertex and vertex . As a result, vertex and vertex are connected to each other, while vertex is not connected to any other vertices by an edge.
Thus, and 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