** (FLOYD)COW CONTEST:** <Excerpt in index | 首页摘要>
<The rest of contents | 余下全文>
Cow Contest
Time Limit: 1000 MS Memory Limit: 65536 K
Total Submit: 224(75 users) Total Accepted: 93(69 users) Rating: Special Judge: No
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 * Lines 2..M+1: Each line contains two space-separated integers that describe the competitors and results (the first integer, A, is the winner) of a single round of competition: A and B
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头奶 牛都差。而编号为5的奶牛又输在了她的手下,也就是说,她的水平比编号 为5的 奶牛强一些。于是,编号为2的奶牛的排名必然为第4,编号为5的奶牛的水平必 然最差。其他3头奶牛的排名仍无法确定。
一开始写出了这样的代码:
1 | #include<iostream> |
runtimeerro,可能是递归太深了
用Floyd算法:
1 | #include<iostream> |