Panda and Destruction

4.6

18 votes
Problem

There is a country which is infected by virus. It has many cities and some cities are connected to other cities. In order to prevent virus from spreading Panda plans on destroying the connection between all the cities. Panda has got a power called pimogio. Using this power he can destroy any city, which results in destruction of all connections from this city. For destroying one city, Panda requires one unit pimogio power. Panda's final aim is to isolate all the cities. In order to do so, Panda follows a simple approach, he keeps on destroying the city with most number of connections in it at that moment.
Since Panda is weak in calculation, please help him in finding out the units of pimogio power required by him to achieve his aim. There cannot be multiple connections between two cities i.e. two cities can have only one road connected to them.
Note: If there are multiple cities with highest connections, destroy the city with the lowest index.

Input Format:
The first line will contain 2 space separated integers N and M, where N is the number of cities in Panda's town and M is the number of connections that the cities have.
Next M lines follow, each line consists of two integers A and B, specifying that city A has a connection with city B and B has a connection with the city A.

Output Format:
For each test case, output the minimum energy that Panda requires to achieve his aim.

Constraints:
1 <= N <= 105
1 <= M <= 3 * 105
1 <= A,B <= N

Image for sample Test case:
enter image description here

Time Limit: 3
Memory Limit: 256
Source Limit:
Explanation

We can either destroy the cities numbered:
i.. 1 and 3, or
ii. 2 and 3, or
iii. 1 and 4, or
iv. 2 and 4
to achieve Panda's aim.

Editor Image

?