HDU 1869 six-degree Separation

Source: Internet
Author: User

HDU 1869 six-degree Separation
 Six-degree SeparationTime Limit: 5000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission (s): 5035 Accepted Submission (s): 2026



Problem Description in 1967, the famous American sociologist Stanley milgranm proposed a famous hypothesis named "small world phenomenon, A maximum of six people can be associated with each other with only six people, therefore, his theory is also called six degrees of separation ). Although milgalham's theory has been often fulfilled and many scientists have always been interested in it, it has never been rigorously proven over the past 30 years, it's just a legend.

Lele is very interested in this theory, so he investigates N people in HDU. He has known the relationship between them. Now, please help him verify whether "Six-Degree separation" is true.
Input this question contains multiple groups of tests, please process until the end of the file.
For each group of tests, the first line contains two integers N, M (0 Next there are M rows, each line has two integers A, B (0 <= A, B Except for the M group relationship, no one else knows each other.

For each group of tests, if the data conforms to the "Six-Degree separation" theory, "Yes" is Output in one row; otherwise, "No" is Output ".
Sample Input

8 70 11 22 33 44 55 66 78 80 11 22 33 44 55 66 77 0

Sample Output
YesYes

Author linle
Source 2008 select-out competition for the Hangzhou electric training team-warm-up competition

Start with and check the set .. WA twice .. In fact, it is the floyd algorithm to find the transfer closure. We can assume that the distance between two people is 1. Unknown is infinity. Floyd: after finding the passed closure, if the distance is greater than 7, it is No. Because the first person and the seventh person can be separated by a maximum of six people .. So the distance from him is 7. If the value is greater than seven, the six-degree separation is not satisfied ..
# Include
 
  
# Include
  
   
# Include
   
    
# Include
    # Include
     
      
# Include
      
        # Include
       
         # Include
        
          # Include
         
           # Include
          
            # Include using namespace std; # define inf 0x6f6f6f # define mod 10int mat [105] [105]; int main () {int I, j, k; int n, m; while (cin> n> m) {int a, B, flag; flag = 1; for (I = 0; I
           
             > A> B; mat [a] [B] = mat [B] [a] = 1; // The recognition distance is 1.} for (k = 0; k
            
              Mat [I] [k] + mat [k] [j]) mat [I] [j] = mat [I] [k] + mat [k] [j]; // find the closure} for (I = 0; I
             
               7) // enumerate any two people. If the value is greater than seven, No is returned. {Flag = 0; break ;}} if (! Flag) break;} if (! Flag) printf ("No \ n"); else printf ("Yes \ n");} return 0 ;}
             
            
           
          
         
        
       
      
     
   
  
 

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.