958B1.md (1832B)
1 Source: https://codeforces.com/problemset/problem/958/B1 2 3 B1. Maximum Control (easy) 4 5 time limit per test 6 7 2 seconds 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 The Resistance is trying to take control over all planets in a particular solar system. This solar system is shaped like a tree. More precisely, some planets are connected by bidirectional hyperspace tunnels in such a way that there is a path between every pair of the planets, but removing any tunnel would disconnect some of them. 22 23 The Resistance already has measures in place that will, when the time is right, enable them to control every planet that is not remote. A planet is considered to be remote if it is connected to the rest of the planets only via a single hyperspace tunnel. 24 25 How much work is there left to be done: that is, how many remote planets are there? 26 27 Input 28 29 The first line of the input contains an integer *N* (2 ≤ *N* ≤ 1000) – the number of planets in the galaxy. 30 31 The next *N* - 1 lines describe the hyperspace tunnels between the planets. Each of the *N* - 1 lines contains two space-separated integers *u* and *v* (1 ≤ *u*, *v* ≤ *N*) indicating that there is a bidirectional hyperspace tunnel between the planets *u* and *v*. It is guaranteed that every two planets are connected by a path of tunnels, and that each tunnel connects a different pair of planets. 32 33 Output 34 35 A single integer denoting the number of remote planets. 36 37 Examples 38 39 Input 40 41 ``` 42 5 43 4 1 44 4 2 45 1 3 46 1 5 47 ``` 48 49 Output 50 51 ``` 52 3 53 ``` 54 55 Input 56 57 ``` 58 4 59 1 2 60 4 3 61 1 4 62 ``` 63 64 Output 65 66 ``` 67 2 68 ``` 69 70 Note 71 72 In the first example, only planets 2, 3 and 5 are connected by a single tunnel. 73 74 In the second example, the remote planets are 2 and 3. 75 76 Note that this problem has only two versions – easy and medium.