POJ-3660-Cow Contest (floyd evaluate the passed closure)

Source: Internet
Author: User

POJ-3660-Cow Contest (floyd evaluate the passed closure)
Cow Contest

Thought: floyd calculates the transfer closure, which is used to determine whether each vertex can reach another vertex. Then, based on the number of points that can be reached and the sum of the number of times that can be reached is equal to n-1, to determine whether the point has been ranked

AC code:

#include#include 
   
    #include 
    
     #include 
     
      #include 
      
       #include 
       
        #include 
        
         #include 
         
          #include 
          
           #include 
           
            #include 
            
             #include 
             
              #include 
              
               #include #define LL long long#define INF 0x7fffffffusing namespace std;int mp[105][105];int n, m;int main() { while(scanf(%d %d, &n, &m) != EOF) { int u, v; memset(mp, 0, sizeof(mp)); for(int i = 0; i < m; i ++) { scanf(%d %d, &u, &v); mp[u][v] = 1; } for(int k = 1; k <= n; k ++) { for(int i = 1; i <= n; i ++) { for(int j = 1; j <= n; j ++) { mp[i][j] = (mp[i][j] | (mp[i][k] & mp[k][j]) ); } } } for(int i = 1; i <= n; i ++) mp[i][i] = 0; int ans = 0; for(int i = 1; i <= n; i ++) { int cnt = 0; for(int j = 1; j <= n; j ++) { cnt += mp[i][j]; cnt += mp[j][i]; } if(cnt == n-1) ans ++; }www.bkjia.com printf(%d, 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.