Poj-3660 Cow Contest

Source: Internet
Author: User

Poj-3660 Cow Contest

Link: www.bkjia.com

Use floyd to pass the closure to determine the outcome. In this way, all vertices a can reach are ranked after. All the points that can go to a are ranked before. For example, if the sum of "A", "ranking before" and "ranking after" is "n-1", the ranking is definite.

 

 

#include 
 
  #include 
  
   #include 
   
    #include 
    
     #include 
     
      using namespace std;const int MAX = 110;int n,m;int rank[MAX][MAX];int in[MAX] ,out[MAX];int ans;int main (){    int a,b;    while (cin>>n>>m)    {        memset(rank,0,sizeof(rank));        memset(in,0,sizeof(in));        memset(out,0,sizeof(out));        ans = 0;        while (m--)        {            cin>>a>>b;            rank[a][b] = 1;        }        for(int k=1;k<=n;k++)            for(int i=1;i<=n;i++)            for(int j=1;j<=n;j++)        {            if (rank[i][k] == 1 && rank[k][j] == 1)                rank[i][j] =1;        }        for(int i=1;i<=n;i++)        {            int res = 0;            for(int j=1;j<=n;j++)                res += rank[i][j] + rank[j][i];            if (res == n-1)                ans++;        }        cout<
      

 

 

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.