Cow Contest | ||||||
| ||||||
Description | ||||||
N (1 ≤ N ≤ 100) cows, conveniently numbered 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 has a greater skill level than cow B (1 ≤ A ≤ N; 1 ≤ B ≤ N; A ≠ 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 (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. | ||||||
Input | ||||||
For each test case: * Line 1: Two space-separated integers: N and M Process to the end of file. | ||||||
Output | ||||||
For each test case: * Line 1: A single integer representing the number of cows whose ranks can be determined | ||||||
Sample Input | ||||||
5 5
4 3 4 2 3 2 1 2 2 5 | ||||||
Sample Output | ||||||
2
| ||||||
Hint | ||||||
编号为2的奶牛输给了编号为1、3、4的奶牛,也就是说她的水平比这3头奶
题意:给出奶牛的关系,找出能确定排名的奶牛个数。
|
Floyd传递闭包 hrbust 1018
最新推荐文章于 2024-04-30 21:32:14 发布