eolymp
bolt
Try our new interface for solving problems
Problems

Cow Contest

Cow Contest

$n$ cows, numbered from $1$ to $n$, participate in a programming contest. As we all know, some cows code better than others. Each cow has a certain constant skill rating that is unique among the competitors. The contest is conducted in several head-to-head rounds, each between two cows. If cow $a$ has a greater skill level than cow $b~(1 \le a, b \le n, a \ne b)$, then cow $a$ will always beat cow $b$. Farmer John is trying to rank the cows by skill level. Given a list the results of $m$ two-cow rounds, determine the number of cows whose ranks can be precisely determined from the results. It is guaranteed that the results of the rounds will not be contradictory. \InputFile The first line contains two integers $n~(1 \le n \le 100)$ and $m~(1 \le m \le 4500)$. Each of the next $m$ lines contains two integers that describe the competitors and results (the first integer $a$, is the winner) of a single round of competition: $a$ and $b$. \OutputFile Print a single integer representing the number of cows whose ranks can be determined. \includegraphics{https://static.e-olymp.com/content/90/909fe28782eab741e73231976cd1e880081b4605.gif}
Time limit 1 second
Memory limit 128 MiB
Input example #1
5 5
4 3
4 2
3 2
1 2
2 5
Output example #1
2
Source 2008 USACO January Silver