SUBMERGE - Submerging Islands


Vice City is built over a group of islands, with bridges connecting them. As anyone in Vice City knows, the biggest fear of vice-citiers is that some day the islands will submerge. The big problem with this is that once the islands submerge, some of the other islands could get disconnected. You have been hired by the mayor of Vice city to tell him how many islands, when submerged, will disconnect parts of Vice City. You should know that initially all the islands of the city are connected.

Input

The input will consist of a series of test cases. Each test case will start with the number N (1 ≤ N ≤ 10^4) of islands, and the number M of bridges (1 ≤ M ≤ 10^5). Following there will be M lines each describing a bridge. Each of these M lines will contain two integers Ui, Vi (1 ≤ Ui,Vi ≤ N), indicating that there is a bridge connecting islands Ui and Vi. The input ends with a case where N = M = 0.

Output

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.

Example

Input:
3 3
1 2
2 3
1 3
6 8
1 3
6 1
6 3
4 1
6 4
5 2
3 2
3 5
0 0


Output:
0
1

hide comments
updown: 2017-05-31 22:28:37

I was getting WA but I used this test to debug my code. Here is a test case
Input:
5 5
1 2
1 5
2 5
5 3
3 4
4 3
4 1
1 2
2 3
7 8
7 2
7 1
1 2
1 6
1 4
1 3
3 5
4 5
0 0

Output:
2
2
1

kira28: 2017-04-10 12:15:59

This is a classical problem .
Java users must be getting NZEC due to StackOverflowError as the java runtime stack size (by default) is very small.
You will have to increase the stack size by using the constructor of java.lang.Thread :)

Last edit: 2017-04-10 12:16:40
anurag_tangri: 2017-04-06 22:23:08

easy problem. learnt Tarjans algorithm :)

Last edit: 2017-04-06 22:23:37
flyingduchman_: 2017-02-27 19:09:26

Learn to find Articulation Points (or Cut Vertices) in a Graph from geeksforgeeks and a tutorial video** first or get yourself submerged

Last edit: 2017-02-27 19:10:31
vengatesh15: 2017-02-20 16:19:51

easy one in graph :-)

siddharth_0196: 2016-12-30 10:22:35

Direct implementation of algorithm.
200! :D

lukaszpolska: 2016-12-27 00:16:39

Is there somebody who had wa and now has ac and can give some tests. I don't know why i have wa.

Last edit: 2016-12-27 00:22:19
gauravm788: 2016-08-24 22:03:48

Plz help...Why am I getting wrong answer..Sub ID (17574745)? My code passes all test cases on spoj toolkit

avisheksanvas: 2016-08-10 16:00:42

Just the Algorithm. Straight. :)

sanjay: 2016-07-01 13:23:24

Just finding Articulation points in the given connected graph.Nice revision for graph lover's.Thank's for the author.


Added by:Hector Navarro
Date:2013-05-16
Time limit:1s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: ASM64
Resource:MiniMaraton 2013 - UCV