659E.md (3175B)
1 Source: https://codeforces.com/problemset/problem/659/E 2 3 E. New Reform 4 5 time limit per test 6 7 1 second 8 9 memory limit per test 10 11 256 megabytes 12 13 input 14 15 standard input 16 17 output 18 19 standard output 20 21 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. 22 23 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). 24 25 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. 26 27 Help the Ministry of Transport to find the minimum possible number of separate cities after the reform. 28 29 Input 30 31 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). 32 33 Next *m* lines contain the descriptions of the roads: the *i*-th road is determined by two distinct integers *x**i*, *y**i* (1 ≤ *x**i*, *y**i* ≤ *n*, *x**i* ≠ *y**i*), where *x**i* and *y**i* are the numbers of the cities connected by the *i*-th road. 34 35 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. 36 37 Output 38 39 Print a single integer — the minimum number of separated cities after the reform. 40 41 Examples 42 43 Input 44 45 ``` 46 4 3 47 2 1 48 1 3 49 4 3 50 ``` 51 52 Output 53 54 ``` 55 1 56 ``` 57 58 Input 59 60 ``` 61 5 5 62 2 1 63 1 3 64 2 3 65 2 5 66 4 3 67 ``` 68 69 Output 70 71 ``` 72 0 73 ``` 74 75 Input 76 77 ``` 78 6 5 79 1 2 80 2 3 81 4 5 82 4 6 83 5 6 84 ``` 85 86 Output 87 88 ``` 89 1 90 ``` 91 92 Note 93 94 In the first sample the following road orientation is allowed: , , . 95 96 The second sample: , , , , . 97 98 The third sample: , , , , .