Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 6318 Accepted Submission(s): 2555
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
Yes Yes
还是喜欢用弗洛伊德,感觉好好,代码好理解而且还短~~~还是模板题~~
#include<stdio.h> #define INF 9999999 #define min(a, b) a < b ? a : b int map[210][210]; void floyd(int n){ int i, j, k; for(k = 0; k < n; ++k){ for(i = 0; i < n; ++i){ for(j = 0; j < n; ++j){ map[i][j] = min(map[i][j], map[i][k] + map[k][j]); } } } } int main(){ int n, m; while(~scanf("%d%d", &n, &m)){ int i, j, k, flag = 0; for(i = 0; i <= n; ++i){ for(j = 0; j <= n; ++j){ if(i == j) map[i][j] = 0; else map[i][j] = INF; } } for(k = 0; k < m; ++k){ scanf("%d%d", &i, &j); map[i][j] = map[j][i] = 1; } floyd(n); for(i = 0; i < n; ++i){ for(j = 0; j < n; ++j){ if(map[i][j] > 7){ flag = 1; break; } } } if(flag) printf("No\n"); else printf("Yes\n"); } return 0; }