Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1791 Accepted Submission(s): 696
#include<stdio.h> #include<string.h> #define INF 0x3f3f3f3f int vis[110],map[110][110],dis[110]; int n,m; void init(){ int i,j; for(i=0;i<n;i++) for(j=0;j<n;j++){ if(j==i) map[i][j]=map[j][i]=0; else map[i][j]=map[j][i]=INF; } } void dijkstra(int beg){ int i; memset(vis,0,sizeof(vis)); for(i=0;i<n;i++) dis[i]=map[beg][i]; for(i=0;i<n;i++){ int j,k,temp=INF; for(j=0;j<n;j++) if(!vis[j]&&temp>dis[j]) temp=dis[k=j]; if(temp==INF) break; vis[k]=1; for(j=0;j<n;j++) if(!vis[j]&&dis[j]>dis[k]+map[k][j]) dis[j]=dis[k]+map[k][j]; } } int main(){ while(scanf("%d%d",&n,&m)!=EOF){ init(); for(int i=0;i<m;i++){ int a,b; scanf("%d%d",&a,&b); map[a][b]=map[b][a]=1; } int i,j,max=-1; for(i=0;i<n;i++){ dijkstra(i); for(j=i;j<n;j++){ if(max<dis[j]) max=dis[j]; } } if(max>7) printf("No\n"); else printf("Yes\n"); } return 0; }
版权声明:本文为博主原创文章,未经博主允许不得转载。
原文地址:http://blog.csdn.net/gui951753/article/details/47759253