Title: Click to open link
Code:
#include <stdio.h> #include <algorithm> #define INF 0x3f3f3f3fusing namespace Std;int m,n;int cost[110][110] , D[110];bool used[110];void distr (int x) {for (int i=0;i<m;i++) {d[i]=inf;used[i]=false;} D[x]=0;while (true) {int v=-1;for (int u=0;u<m;u++) if (!used[u]&& (v==-1| | D[U]<D[V]) v=u;used[v]=true;if (v==-1) break;for (int u=0;u<m;u++) d[u]=min (D[u],d[v]+cost[v][u]);}} int main () {while (~scanf ("%d%d", &m,&n)) {int i,j;int k=0;int a,b;for (i=0;i<m;i++) for (j=0;j<m;j++) cost[i][j]=inf;for (i=0;i<n;i++) {scanf ("%d%d", &a,&b); cost[a][b]=1;cost[b][a]=1;} for (i=0;i<m;i++)//Ensure that there are no more than seven contacts per two persons {distr (i); for (j=i;j<m;j++) {if (d[j]>7) { k=1; Break;}} if (k) break;} if (k) printf ("no\n"); elseprintf ("yes\n"); } return 0;}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Hdu OJ 18,696 degree separation