DAY 5 - Burning bridges

0

0 votes
Graph Theory, Strongly Connected Components, Implementation, Graph, Recruit, Ready, Medium, Algorithms, Grammar-Verified, Approved
Problem

You are given a map which contains N islands that are connected by M bridges. You are also given Q queries, each of which specify an island to be deleted. Once an island is deleted, all the bridges (if any) connected to the island are also deleted.

Write a program to find the number of pairs of islands that are no longer connected after each query is implemented.

Note:

For each new query, assume the initial unmodified map.

Input format

  • First line: Two space-separated integers N and M
  • Next M lines: Two space-separated integers A and B (denoting a bridge between A and B
  • Next line: Q
  • Next Q lines: Integer i denoting the island to be deleted

Output format

For each query, print the number of pairs of disconnected islands.

Constraints

1N,Q105
1A,BN
0Mmin(105,N(N1)/2)

Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

For the 2nd query, when Island 2 gets deleted, Island 1 cannot reach Island 3 and Island 4. Hence, the output is 2.

Participants are requested to keep themself updated with the announcements of the contest.

Editor Image

?