POJ-3660-Co-Contest
题目描述:
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.
输入:
- 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
输出:
Line 1: A single integer representing the number of cows whose ranks can be determined
输入示例:
1 | 5 5 |
输出示例:
1 | 2 |
题目大意:
有N头牛,现在给出M个输赢列表(第一代表赢,第二代表输),并且实力是绝对的(这句话很重要)。要求你确定谁的排名是确定的,输出确定的个数。
思路:
使用传递闭包来确定赢的关系,并通过判断其中一头牛与其他牛是否都有联系(赢了别的牛,或输给了别的牛)。如果与其余N-1条牛都有联系,说明该牛的排名是确定的。
Solution:
1 | #include<iostream> |