AlgoUniversity
  • Go Back
Discussion
Cities And Explosions :

Author

Ayush Gangwani

Difficulty Level : Medium

Submissions : 416

Asked In : PhonePe

Marks :15

: 18 | : 0

There are $$$n$$$ cities $$$(1, 2,......., n)$$$ and $$$m$$$ roads and the cities are connected to other cities by those roads. Terrorists have planted bombs in every city. Each bomb will explode one after the other. First bomb in city $$$1$$$ will explode, then city $$$2$$$ and so on.

Each explosion will destroy the city and the roads which are connected to it.

After every explosion, you need to return the number of connected components of cities.

Input

The first line of each testcase contains two space separated integers $$$n$$$ $$$(1 \le n \le 10^5)$$$ and $$$m$$$ $$$(1 \le m \le min(n,2 \cdot 10^5)$$$ — the number of cities and the number of roads.

The next $$$m$$$ lines contain two space separated integers $$$u$$$ and $$$v$$$ $$$(1 \le u,v \le n)$$$ each denoting that there is a road between city number $$$u$$$ and city number $$$v$$$.

Output

Print $$$n$$$ integers each in a new line — $$$i^{th}$$$ integer should be the number of connected components after the $$$i^{th}$$$ node explodes.

Example

Input
6 7
1 2
1 4
1 5
2 4
2 3
3 5
3 6
Output
1
2
3
2
1
0

Note

For the sample test case, the following images show the number of components after successive explosion of the cities.

state of the graph after successive explosion of cities.

You need to login to view your submissions.

You need to login to view all submissions.

Loading...

Result : Executed

Loading...

Feel something is wrong with the test cases?

Result : Accepted

Test Cases :

You need to Log In
We're glad that you want to attempt this problem!

But to Run or Submit the Problem, you need to Log In.

Continue to Log In
Challenge Submitted!

Your challenge has been submitted successfully.

You will get a response soon via WhatsApp or Email.

Challenge
Facing issue while trying to solve the problem! Don't worry, we got you covered!

Do let us know your issue.

Looks good!
Please enter your issue / feedback.

How do we get in touch with you?
Looks good!
Please enter your phone no.
Looks good!
Please enter your email address.