POJ 3660 Cow Contest
Cow Contest
Time Limit:1000 MS |
|
Memory Limit:65536 K |
Total Submissions:7628 |
|
Accepted:4243 |
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 conducting CTED in several head-to-head rounds, each between two cows. If cowAHas a greater skill level than cowB(1 ≤A≤N; 1 ≤B≤N;A=B), Then cowAWill always beat cowB.
Farmer John is trying to rank the cows by skill level. Given a list the resultsM(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 contradic.pdf.
Input
* Line 1: Two space-separated integers:NAndM
* 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:AAndB
Output
* Line 1: A single integer representing the number of cows whose ranks can be determined
Sample Input
5 54 34 23 21 22 5
Sample Output
2
// The order in which ox A can defeat ox B is determined.
// Record the degree of each ox, if equal to the N-1 indicates the order can be determined.
#include
#include
#include
#include
#include
#include #define N 109using namespace std;int mp[N][N];int n,m;int a,b;int deg[N];int main(){ while(~scanf("%d %d",&n,&m)) { memset(deg,0,sizeof deg); memset(mp,0,sizeof mp); for(int i=1;i<=m;i++) { scanf("%d %d",&a,&b); mp[a][b]=1; } for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) for(int k=1;k<=n;k++) if(mp[j][i] && mp[i][k]) mp[j][k]=1; for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) { if(mp[i][j]) { deg[i]++; deg[j]++; } } int ans=0; for(int i=1;i<=n;i++) if(deg[i]==n-1) ans++; printf("%d\n",ans); } return 0;}