标签:
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1869
Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 5171 Accepted Submission(s):
2089
1 #include <iostream> 2 #include <cstdio> 3 4 using namespace std; 5 6 const int INF=999999; 7 8 int Map[210][210],n; 9 10 int settle() 11 { 12 for (int i=0; i<n; i++) 13 { 14 //node[i]=INF; 15 for (int j=0; j<n; j++) 16 { 17 Map[i][j]=INF; 18 } 19 } 20 } 21 22 int floyd() 23 { 24 for (int k=0; k<n; k++) 25 { 26 for (int i=0; i<n; i++) 27 { 28 for (int j=0; j<n; j++) 29 { 30 if (Map[i][j]>Map[i][k]+Map[k][j]) 31 Map[i][j]=Map[i][k]+Map[k][j]; 32 } 33 } 34 } 35 36 } 37 38 int main() 39 { 40 int m; 41 while (~scanf("%d%d",&n,&m)) 42 { 43 settle(); 44 while (m--) 45 { 46 int a,b; 47 scanf("%d%d",&a,&b); 48 Map[a][b]=Map[b][a]=1; 49 } 50 floyd(); 51 int MAx=0; 52 for (int i=0; i<n; i++) 53 { 54 for (int j=0; j<n; j++) 55 { 56 if (MAx<Map[i][j]) 57 MAx=Map[i][j]; 58 } 59 } 60 if (MAx>7) 61 printf ("No\n"); 62 else 63 printf ("Yes\n"); 64 } 65 return 0; 66 }
标签:
原文地址:http://www.cnblogs.com/qq-star/p/4498687.html