codeforces-scrape

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

315A.md (1256B)


      1 Source: https://codeforces.com/problemset/problem/315/A
      2 
      3 A. Sereja and Bottles
      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 stdin
     16 
     17 output
     18 
     19 stdout
     20 
     21 Sereja and his friends went to a picnic. The guys had *n* soda bottles just for it. Sereja forgot the bottle opener as usual, so the guys had to come up with another way to open bottles.
     22 
     23 Sereja knows that the *i*-th bottle is from brand *a**i*, besides, you can use it to open other bottles of brand *b**i*. You can use one bottle to open multiple other bottles. Sereja can open bottle with opened bottle or closed bottle.
     24 
     25 Knowing this, Sereja wants to find out the number of bottles they've got that they won't be able to open in any way. Help him and find this number.
     26 
     27 Input
     28 
     29 The first line contains integer *n* (1 ≤ *n* ≤ 100) — the number of bottles. The next *n* lines contain the bottles' description. The *i*-th line contains two integers *a**i*, *b**i* (1 ≤ *a**i*, *b**i* ≤ 1000) — the description of the *i*-th bottle.
     30 
     31 Output
     32 
     33 In a single line print a single integer — the answer to the problem.
     34 
     35 Examples
     36 
     37 Input
     38 
     39 ```
     40 4  
     41 1 1  
     42 2 2  
     43 3 3  
     44 4 4
     45 ```
     46 
     47 Output
     48 
     49 ```
     50 4
     51 ```
     52 
     53 Input
     54 
     55 ```
     56 4  
     57 1 2  
     58 2 3  
     59 3 4  
     60 4 1
     61 ```
     62 
     63 Output
     64 
     65 ```
     66 0
     67 ```