POJ 3660 Cow Contest

Source: Internet
Author: User
Tags rounds

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 ≤AN; 1 ≤BN;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;}
     
    
   
  
 


 

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.