atcoder#ABC302E. [ABC302E] Isolation
[ABC302E] Isolation
Score : points
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.
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 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.
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.