#P2419. [USACO08JAN] Cow Contest S

    ID: 1416 远端评测题 1000ms 125MiB 尝试: 0 已通过: 0 难度: 5 上传者: 标签>2008USACO深度优先搜索,DFS拓扑排序

[USACO08JAN] Cow Contest S

Description

N(1N100) N (1 ≤ N ≤ 100) cows, conveniently numbered 1 N 1 ~ N , are participating 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 A has a greater skill level than cow B(1AN;1BN;AB) B (1 ≤ A ≤ N; 1 ≤ B ≤ N; A ≠ B) , then cow A A will always beat cow B B .

Farmer John is trying to rank the cows by skill level. Given a list the results of M(1M4,500) M (1 ≤ M ≤ 4,500) 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.

5 5
4 3
4 2
3 2
1 2
2 5
2