标签:
Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 5443 Accepted Submission(s): 2208
#include<stdio.h> #include<string.h> #define MAX 1000 #define INF 0x3f3f3f int map[MAX][MAX],vis[MAX]; int low[MAX]; int n,m; int ok; void prime(int y,int x) { int i,j,next; int min,mincost=0; memset(vis,0,sizeof(vis)); for(i=0;i<n;i++) { low[i]=map[y][i]; } vis[y]=1; for(i=0;i<n-1;i++) { min=INF; for(j=0;j<n;j++) { if(!vis[j]&&min>low[j]) { min=low[j]; next=j; } } vis[next]=1; for(j=0;j<n;j++) { if(!vis[j]&&low[j]>map[next][j]+low[next]) low[j]=map[next][j]+low[next]; } } if(low[x]==INF||low[x]-1>6) { ok=0; printf("No\n"); } } int main() { int j,i,s,t,l; int a,b; while(scanf("%d%d",&n,&m)!=EOF) { for(i=0;i<n;i++) { for(j=0;j<n;j++) { if(i==j) map[i][j]=map[j][i]=0; else map[i][j]=INF; } } for(i=0;i<m;i++) { scanf("%d%d",&a,&b); map[a][b]=map[b][a]=1; } ok=1; for(j=0;j<n;j++) { for(i=0;i<n;i++) { prime(j,i); if(ok==0) break; } if(ok==0) break; } if(ok) printf("Yes\n"); } return 0; }
标签:
原文地址:http://www.cnblogs.com/tonghao/p/4671371.html