思路:
模拟,用两位vector表示edge相连关系
然后,看是否两两相连和是否有其他点与其都相连
src
// 不需要并查
#include<bits/stdc++.h>
using namespace std;
vector<vector<int>> edge(250, vector<int>(250, 0));
int main() {
int n, m;
cin >> n >> m;
for(int i = 0; i < m; i++) {
int x, y;
cin >> x >> y;
edge[x][y] = edge[y][x] = 1;
}
int k;
cin >> k;
for(int i = 1; i <= k; i++) {
int l;
cin >> l;
vector<int> v(l);
for(int j = 0; j < l; j++)
cin >> v[j];
bool flag1 = true;
for(int j = 0; j < l; j++) {
for(int k = j + 1; k < l; k++){
//cout << v[j] << " " << v[k] << " " << edge[v[j]][v[k]] << endl;
if(edge[v[j]][v[k]] == 0) {
flag1 = false;
break;
}
}
if(flag1 == false) break;
}
bool flag2 = false;
int minn = -1;
for(int j = 1; j <= n; j++) {
int k;
for(k = 0; k < l; k++) {
if(j == v[k]) break;
if(j != v[k] && edge[j][v[k]] == 0) break;
}
if(k == l) {
flag2 = true;
minn = j;
break;
}
}
if(flag1 == false) printf("Area %d needs help.\n", i);
else if(flag2) printf("Area %d may invite more people, such as %d.\n", i, minn);
else printf("Area %d is OK.\n", i);
}
}