Foxlings

View as PDF

Submit solution

Points: 10 (partial)
Time limit: 1.0s
Memory limit: 16M

Author:
Problem type

It's Christmas time in the forest, and both the fox and the wolf families are celebrating. The rather large fox family consists of two parents as well as N (1 \le N \le 1\,000\,000\,000) little foxlings. The parents have decided to give their children a special treat this year – crackers! After all, it's a well-known fact that foxen love crackers.

With such a big family, the parents can't afford that many crackers. As such, they wish to minimize how many they give out, but still ensuring that each foxling gets at least a bit. The parents can only give out entire crackers, which can then be divided and passed around.

With this many children, not all of them know one another all that well. The foxlings have names, of course, but their parents are computer scientists, so they have also conveniently numbered them from 1 to N. There are M (0 \le M \le 100\,000) unique two-way friendships among the foxlings, where relationship i is described by the distinct integers A_i and B_i (1 \le A_i, B_i \le N), indicating that foxling A_i is friends with foxling B_i, and vice versa. When a foxling is given a cracker, he can use his tail to precisely split it into as many pieces as he wants (the tails of foxen have many fascinating uses). He can then pass these pieces around to his friends, who can repeat this process themselves.

Input Specification

Line 1: Two integers – N and M.
Next M lines: Two integers – A_i and B_i.

Output Specification

The minimum number of crackers that must be given out so that each fox ends up with at least a bit of a cracker.

Sample Input

9 5
3 1
6 1
7 6
2 7
8 9

Sample Output

4

Explanation

The parents can give one cracker to foxling 6, who will then split it into three and give pieces to his friends (foxlings 1 and 7). Foxling 7 can then give half of his piece to his other friend, foxling 2.

They can give another cracker to foxling 8, who will split it with foxling 9.

This leaves foxlings 4 and 5, who have no friends (don't worry, foxen have long since outgrown the need for friends), and who must be given one cracker each. This brings the total up to 4 crackers.


Comments

There are no comments at the moment.