408777: GYM103316 D Feeding the Earth Kingdom

Memory Limit:256 MB Time Limit:1 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

D. Feeding the Earth Kingdomtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard output

Recent turmoil has left the people of the Earth Kingdom more disconnected than ever. The people lack contact with the outside world and are starting to go hungry. No worries, Avatar Korma is here to save the day!

Korma has analyzed the area and realized that the $$$N$$$ villages (numbered $$$1...N$$$) of the Earth Kingdom are left with only $$$M$$$ roads (which are traversable in both directions). Furthermore, the road infrastructure of the kingdom has been so damaged that every pair of villages has either one or no paths between each other. In addition, they don't have any food!

Faced with this issue, Korma has a plan. Korma will airlift food shipments to some of these villages and with the magic of friendship, she knows that the villagers are incredibly generous and will share food with other villages, if they're able to transport it.

Given the existing roads, Help Korma determine the minimal number of food shipments she will need to feed all the villages.

Input

The first line contains two integers, $$$1 \leq N \leq 10^5$$$ and $$$0 \leq M \leq 10^5$$$.

The next M lines contain a pair of integers $$$A$$$ and $$$B$$$, where $$$1 \leq A, B \leq N$$$ and $$$A \neq B$$$, denoting an existing road connecting villages $$$A$$$ and $$$B$$$.

Output

A single integer denoting the minimal number of food shipments needed to feed all villagers.

ExampleInput
5 3
4 2
2 1
5 3
Output
2
Note

The provided roads are bidirectional and unique.

加入题单

上一题 下一题 算法标签: