hdoj--1869--Six degree separation

Source: Internet
Author: User

Six degree separation

Time limit:5000/1000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 1791 Accepted Submission (s): 696


Problem Description1967, the famous American sociologist Stanley Milgram proposed a famous hypothesis known as the "Small World phenomenon (small earth phenomenon)", to the effect that there are only 6 people among any 2 strangers, That is, only 6 people can connect them together, so his theory is also known as the "Six degree separation" theory (six Degrees of separation). Although Milgram's theory has often been fulfilled, there have been many sociologists interested in it, but in more than 30 years, it has never been a rigorous proof, but a legendary hypothesis.

Lele was quite interested in the theory, so he investigated n individuals in the HDU. He has got the relationship between them, now ask you to help him to verify the "Six Degrees of separation" is the establishment of it.

Input This topic contains multiple sets of tests, please handle to the end of the file.
For each set of tests, the first line contains two integers, n,m (0<n<100,0<m<200), representing the number of people in the HDU (0~n-1 numbers respectively), and their relationship.
Next there are m lines, each line of two integers, a, B (0<=a,b<n), which indicates that the people who are numbered a in HDU are acquainted with each other.
In addition to this m-group relationship, no other two people are acquainted.

Output for each set of tests, if the data conforms to the "Six degree separation" theory, it Outputs "Yes" in one line, otherwise the output "No".

Sample INPUT8 7 0 1 1 2 2 3 3 4 4 5 5 6 6 7 8 8 0 1 1 2 2 3 3 4 4 5 5 6 6 7 7 0

Sample outputyes Yes idea: Sum, the weight of each side as 1, and then compare any two points of the distance, to see if there is more than 7, because it is 6 friends, so should be 7 sides can connect any point within. (The first time over a problem, it is absolutely happy not to do so.) ) AC Code:


Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

hdoj--1869--six-degree separation

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.