实在是太粗心了,floyd算法中把k打成了i,找了20分钟才找到错.... 题目不难,最多用6个人就能联系在一起,等价于任意2点的距离不超过7
#include <iostream> #include <algorithm> #include <cstring> using namespace std; #ifndef ONLINE_JUDGE #include <fstream> ifstream fin("test.txt"); #define cin fin #endif int graph[110][110],n,m; const int INF = 1000000; void floyd() { int i,j,k; for(k = 0; k < n; ++k) for(i = 0; i < n; ++i) for(j = 0; j < n; ++j) graph[i][j] = min(graph[i][j],graph[i][k]+graph[k][j]); } bool judge() { for(int i = 0; i < n; ++i) for(int j = i + 1; j < n; ++j) if(graph[i][j] > 7) return 0; return 1; } int main() { ios::sync_with_stdio(false); int a,b; while(cin >> n >> m) { for(int i = 0; i < n; ++i) for(int j = 0; j < n; ++j) if(i == j) graph[i][j] = 0; else graph[i][j] = INF; while(m--) { cin >> a >> b; graph[a][b] = graph[b][a] = 1; } floyd(); if(judge()) cout << "Yes" << endl; else cout << "No" << endl; } return 0; }