Codeforces 659E. New Reform(图论+dfs)

Berland has n cities connected by m bidirectional roads. No road connects a city to itself, and each pair of cities is connected by no more than one road. It is not guaranteed that you can get from any city to any other one, using only the existing roads.

The President of Berland decided to make changes to the road system and instructed the Ministry of Transport to make this reform. Now, each road should be unidirectional (only lead from one city to another).

In order not to cause great resentment among residents, the reform needs to be conducted so that there can be as few separate cities as possible. A city is considered separate, if no road leads into it, while it is allowed to have roads leading from this city.

Help the Ministry of Transport to find the minimum possible number of separate cities after the reform.

Input

The first line of the input contains two positive integers, n and m — the number of the cities and the number of roads in Berland (2 ≤ n ≤ 100 000, 1 ≤ m ≤ 100 000).

Next m lines contain the descriptions of the roads: the i-th road is determined by two distinct integers xi, yi (1 ≤ xi, yi ≤ n, xi ≠ yi), wherexi and yi are the numbers of the cities connected by the i-th road.

It is guaranteed that there is no more than one road between each pair of cities, but it is not guaranteed that from any city you can get to any other one, using only roads.

Output

Print a single integer — the minimum number of separated cities after the reform.

Examples
input

output

input

output

input

output

Note

In the first sample the following road orientation is allowed: , , .

The second sample: , , , , .

The third sample: , , , , .

说实话这道题目比赛的时候没读懂,以为是一开始就是单向边,今天才发现居然是一开始是双向边变成单向边,求出最少的被孤立的点。

注意读入的时候可能并不是只有一个图。我们可以把就一个图分析,可以发现一个结论:如果在一个图中所有的边数等于或者大于节点数的话,那么一定就没有孤立的点。证明的话,我们可以通过树来想,一个树是只有n-1条边却拥有n个点的,那么当我们从根节点dfs的时候,那么除了根节点以外的节点都可以看成有别的节点指向它们。所以当我们多了一条边的时候,就可以形成一个环,从而有节点指向了原先的根节点(这时候再被叫为根节点有点不合适)》。。

所以我们可以遍历所有的根节点(其实是任意选的),判断该根节点是不是可以形成一棵树还是会出现回路,一旦出现树,就说明该根节点就会被孤立。

 

发表评论

电子邮件地址不会被公开。 必填项已用*标注