10311: CF EDU - DSU - Step 3 - C. Dynamic Connectivity Offline
[Creator : ]
Description
You are given an empty undirected graph with $n$ vertices. You have to answer the queries of three types:
- "+ u v" — add an undirected edge u-v to the graph.
- "- u v" — remove an undirected edge u-v from the graph.
- "?" — calculate the number of connected components in the graph.
Input
The first line of the input contains two integers $n,m\ (1 ≤n≤ 3·10^5,\ 0 ≤m≤ 3·10^5)$ — the number of vertices and the number of queries, respectively.
Next $m$ lines contain the description of the queries, one per line. For a query "+" the line looks like "+ u v" (1 ≤u≠v≤n). It is guaranteed that the graph does not contains such an edge. For a query "-" the line looks like "- u v" (1 ≤u≠v≤n). It is guaranteed that the graph contains such an edge. For a query "?" the line looks like "?".
Next $m$ lines contain the desc
Output
For each "?" query, output the number of connected components in the graph at the time of the query on a separate line.
Sample 1 Input
5 11
?
+ 1 2
+ 2 3
+ 3 4
+ 4 5
+ 5 1
?
- 2 3
?
- 4 5
?
Sample 1 Output
5
1
1
2