codeforces-scrape

Codeforces scraped problems and editorials
git clone git://git.laack.co/codeforces-scrape.git
Log | Files | Refs | README

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: ![](https://espresso.codeforces.com/e5b18c46402af724bd3841d549d5d6f52fc16253.png), ![](https://espresso.codeforces.com/04481aced8a9d501ae5d785ab654c542ff5497a1.png), ![](https://espresso.codeforces.com/0d220a75a508edc0d540dbaec5e198345049b66f.png).
     95 
     96 The second sample: ![](https://espresso.codeforces.com/e5b18c46402af724bd3841d549d5d6f52fc16253.png), ![](https://espresso.codeforces.com/030fc9181b578c2d906254d38dc56da5554323eb.png), ![](https://espresso.codeforces.com/29f71c065c3536e88b54429c734103ad3604f68b.png), ![](https://espresso.codeforces.com/a6011a68d6de05246ad6ba8aa24a5c5c71cd450a.png), ![](https://espresso.codeforces.com/0d220a75a508edc0d540dbaec5e198345049b66f.png).
     97 
     98 The third sample: ![](https://espresso.codeforces.com/e5b18c46402af724bd3841d549d5d6f52fc16253.png), ![](https://espresso.codeforces.com/29f71c065c3536e88b54429c734103ad3604f68b.png), ![](https://espresso.codeforces.com/7113d83514735a488d7b85262585381d26986195.png), ![](https://espresso.codeforces.com/98300067e46d036076e429b208db829296ebca9d.png), ![](https://espresso.codeforces.com/146f3f3d208399fbab4d1d8c2800f07bf7b463e5.png).