Hangzhou Electric ACM HDU 18,696 degree separation

Source: Internet
Author: User
Tags time limit
Six degree separation

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


Problem Description in 1967, the famous American sociologist Stanley Milgram proposed a famous hypothesis known as the "Small World phenomenon (small earth phenomenon)", to the effect that No 2 strangers were separated by 6 people, 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 Input

8 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 Output

Yes Yes


Author Linle


Source 2008 Hangzhou Electric Training Team Tryouts--warm-up


Recommend LCY

#include <stdio.h> #include <string.h> #define INF 0x7fffffff #define M-ary int n;
int map[m][m];
int dist[m][m];

int path[m][m];
	void Floyd (int g[m][m],int d[m][m],int p[m][m]) {int i,j,k;
			for (i=0;i<n;i++) {for (j=0;j<n;j++) {d[i][j]=g[i][j];
			if (I!=j&&d[i][j]<inf) p[i][j]=i;
		else P[i][j]=-1;
				}} for (k=0;k<n;k++) {to (i=0;i<n;i++) {for (j=0;j<n;j++) {if (D[i][k]<inf&&d[k][j]<inf)
					if (d[i][j]> (D[i][k]+d[k][j])) {d[i][j]=d[i][k]+d[k][j];
				P[i][j]=k;
    }}}}} void print (int a[m][m]) {int i,j;
        for (i=0;i<n;i++) {for (j=0;j<n;j++) printf ("%d", a[i][j]);
    printf ("\ n");
	}} int main () {int i,j;
	int m;
	int A, B;
		while (~SCANF ("%d%d", &n,&m)) {//memset (map,0,sizeof (map));
		for (i=0;i<n;i++) for (j=0;j<n;j++) Map[i][j]=inf;
			for (i=0;i<m;i++) {scanf ("%d%d", &a,&b);
		Map[a][b]=map[b][a]=1; } Floyd (Map,disT,path);
		Print (dist);
		int flag=1; for (i=0;i<n&&flag;i++) {for (j=i+1;j<n&&flag;j++) if (DIST[I][J]&GT;7) flag
		= 0; } printf ("%s\n", flag?)
	Yes ":" No ");
 }
}


 

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.