A summit (峰会) is a meeting of heads of state or government. Arranging the rest areas for the summit is not a simple job. The ideal arrangement of one area is to invite those heads so that everyone is a direct friend of everyone.
Now given a set of tentative arrangements, your job is to tell the organizers whether or not each area is all set.
Input Specification:
Each input file contains one test case. For each case, the first line gives two positive integers N (≤ 200), the number of heads in the summit, and M, the number of friendship relations. Then M lines follow, each gives a pair of indices of the heads who are friends to each other. The heads are indexed from 1 to N.
Then there is another positive integer K (≤ 100), and K lines of tentative arrangement of rest areas follow, each first gives a positive number L (≤ N), then followed by a sequence of L distinct indices of the heads. All the numbers in a line are separated by a space.
Output Specification:
For each of the K areas, print in a line your advice in the following format:
-
if in this area everyone is a direct friend of everyone, and no friend is missing (that is, no one else is a direct friend of everyone in this area), print
Area X is OK.. -
if in this area everyone is a direct friend of everyone, yet there are some other heads who may also be invited without breaking the ideal arrangement, print
Area X may invite more people, such as H.whereHis the smallest index of the head who may be invited. -
if in this area the arrangement is not an ideal one, then print
Area X needs help.so the host can provide some special service to help the heads get to know each other.
Here X is the index of an area, starting from 1 to K.
Sample Input:
8 10
5 6
7 8
6 4
3 6
4 5
2 3
8 2
2 7
5 3
3 4
6
4 5 4 3 6
3 2 8 7
2 2 3
1 1
2 4 6
3 3 2 1
Sample Output:
Area 1 is OK.
Area 2 is OK.
Area 3 is OK.
Area 4 is OK.
Area 5 may invite more people, such as 3.
Area 6 needs help.
题解:暴力遍历图即可
#include <iostream>
#include <vector>
#include <cstring>
using namespace std;
const int N = 220;
bool e[N][N];
int n, m, k;
int main() {
cin >> n >> m;
for (int i = 0; i < m; i++)
{
int a, b;
cin >> a >> b;
e[a][b] = e[b][a] = true;
}
cin >> k;
vector<int> v;
for (int x = 1; x <= k; x++)
{
bool st[N];
memset(st, false, sizeof(st));
int l;
cin >> l;
v.resize(l);
for (int i = 0; i < l; i++) {
cin >> v[i];
st[v[i]] = true;
}
bool isf = true;
for (int i = 0; i < v.size(); i++)
for (int j = i + 1; j < v.size(); j++)
if (e[v[i]][v[j]] != true) {
isf = false;
break;
}
if (isf == false) cout << "Area " << x << " needs help.";
else {
int add = -1;
for (int i = 1; i <= n; i++)
{
if (st[i]) continue;
bool isconnect = true;
for (int j = 0; j < v.size(); j++)
if (e[i][v[j]] == false) isconnect = false;
if (isconnect) {
add = i; break;
}
}
if (add != -1) {
cout << "Area " << x << " may invite more people, such as " << add << ".";
}
else {
cout << "Area " << x << " is OK.";
}
}
cout << endl;
v.clear();
}
return 0;
}

本文介绍了一种用于安排峰会休息区的算法,确保每个区域内所有参会者都是直接朋友,并探讨了如何判断区域是否理想,是否可以邀请更多人,或者需要特殊帮助以促进交流。

1336

被折叠的 条评论
为什么被折叠?



