2019年冬季PAT甲级7-3
作者:互联网
忘了当时怎么做了。。。
#include <bits/stdc++.h>
using namespace std;
int G[250][250];
vector<vector<int>> v;
int main() {
fill (G[0], G[0] + 250 * 250, 0);
int n, m, a, b, k, len, now;
scanf ("%d %d", &n, &m);
v.resize(n + 1);
for (int i = 0; i < m; i++) {
scanf ("%d %d", &a, &b);
G[a][b] = G[b][a] = 1;
v[a].push_back(b);
v[b].push_back(a);
}
scanf ("%d", &k);
for (int i = 0; i < k; i++) {
scanf ("%d", &len);
int minAns = 999999999, flag = 0, cnt;
set<int> st;
vector<int> vis(n + 1), temp(len);
for (int j = 0; j < len; j++) scanf ("%d", &temp[j]);
for (int j = 0; j < temp.size(); j++) {
// cout <<temp[j] << endl;
for (int u = j + 1; u < temp.size(); u++) {
if (G[temp[j]][temp[u]] == 0) {
// cout << j << " " << u << endl;
flag = 1;
break;
}
}
}
if (flag == 1) printf ("Area %d needs help.\n", i + 1);
else {
vector<int> cnt(n + 1);
for (int j = 0; j < temp.size(); j++) {
for (auto it : v[temp[j]]) {
cnt[it]++;
if (cnt[it] == len) {
st.insert(it);
// cout << "it : " << it << endl;
}
}
}
if (st.size() == 0) printf ("Area %d is OK.\n", i + 1);
else printf ("Area %d may invite more people, such as %d.\n", i + 1, *st.begin());
}
}
}
标签:PAT,temp,int,scanf,len,++,甲级,2019,250 来源: https://blog.csdn.net/YYHCODE/article/details/120118843