410190: GYM103969 J Pudding Passes

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

J. Pudding Passestime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard output

In the mountainous country of Puddia, different cities trade pudding with each other. To traverse through the mountains, there are a number of mountain passes which directly connect two cities together. It is possible to reach every city starting from any city through some sequence of mountain paths.

However, as the leader of the country, you have recently received news on an upcoming storm! Initially, all of the mountain passes are open, but because of the storm, some of these mountain passes might close! In addition, a closed mountain pass could reopen after some time. You have a list of these mountain pass openings and closings, and you want to know the total pairs of distinct cities that can still trade pudding after each event.

Input

The first line of contains two integers $$$n$$$ ($$$2 \leq n \leq 2 \cdot 10^5$$$) and $$$m$$$ ($$$n - 1 \leq m \leq \min(2 \cdot 10^5, \frac{n(n - 1)}{2})$$$), indicating the number of cities and the number of mountain passes, respectively.

The $$$i$$$-th of the next $$$m$$$ lines contains two integers $$$x_i$$$ and $$$y_i$$$ ($$$1 \leq x_i, y_i \leq n, x \neq y$$$) indicating that there is a mountain pass between cities $$$x_i$$$ and cities $$$y_i$$$. It is guaranteed that there do not exist two indices $$$i$$$ and $$$j$$$ where $$$1 \leq i < j \leq n$$$ and either $$$(x_i, y_i) = (x_j, y_j)$$$ or $$$(x_i, y_i) = (y_j, x_j)$$$.

The next line contains a single integer $$$q$$$ ($$$1 \leq q \leq 10^5$$$), indicating the number of updates.

The $$$i$$$-th of the next $$$q$$$ lines contain a single integer $$$c_i$$$ ($$$1 \leq c_i \leq m$$$). If the $$$c_i$$$-th mountain pass was previously open, then the mountain pass is marked as closed in this update. If the $$$c_i$$$-th mountain pass was previously closed, then the mountain pass is marked as open instead.

Output

For each of the $$$q$$$ updates, print the number of pairs of distinct cities that are still connected by some sequence of mountain passes after the update.

ExampleInput
4 4
1 2
2 3
3 4
4 1
8
1
2
3
4
1
2
3
4
Output
6
3
1
0
1
3
6
6

加入题单

算法标签: