Submit Test

Markdown Preview

Add a Code Snippet

Andaman & Nicobar (100 Marks)

Andaman & Nicobar is built over a group of islands, with bridges connecting them. The big problem with Andaman & Nicobar is that once the islands submerge, some of the other islands could get disconnected. You have been hired by the President of India to tell him how many islands, when submerged, will disconnect parts of Andaman & Nicobar. You should know that initially all the islands of the Andaman & Nicobar are connected.

Input Format

The input will consist of a series of test cases. Each test case will start with the number N of islands, and the number M of bridges . Following there will be M lines each describing a bridge. Each of these M lines will contain two integers u and v (1 u,v N), indicating that there is a bridge connecting islands u and v.

Constraints

1 <= N <= 10^4

1 <= M <= 10^5

Output Format

For each case on the input you must print a line indicating the number of islands that, when submerged, will disconnect parts of the city.