1166 Summit
分数 25
作者 陈越
单位 浙江大学
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.
whereH
is 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 <algorithm>
#include <set>
using namespace std;
const int N = 210;
set<int> st[N];
int hs[N];
int main()
{
int n, m, k;
cin >> n >> m;
for(int i=0; i<m; ++i)
{
int u, v;
cin >> u >> v;
st[u].insert(v); //将每个人的直接朋友各自 由一个set来存储
st[v].insert(u);
}
cin >> k;
for(int i=1; i<=k; ++i)
{
fill(hs, hs+N, 0); //清空
set<int> t; //记录检查的朋友编号
int l;
cin >> l;
while(l--)
{
int v;
cin >> v;
t.insert(v);
//如果输入的编号们是直接朋友,那么他们的hs值经过下面的操作
//肯定都是相同的
hs[v]++;
for(auto ele : st[v])
hs[ele]++;
}
//得到最大hs值
int maxd = *max_element(hs, hs+N);
bool flag = true;
for(auto ele : t)
if(hs[ele] != maxd)
flag = false;
//如果有存在不等于maxd的编号,那么这些人中肯定有人不在这个圈子里
int index = -1;
for(int j=1; j<N && index == -1; ++j)
if(hs[j] == maxd && t.find(j) == t.end() && index == -1)
index = j;
//要被邀请的最小编号:存在编号的hs值等于maxd但是又没有在检查的
//输入序列中,那么肯定是漏掉了此人;
printf("Area %d ", i);
if(flag == false)
puts("needs help.");
else if(index == -1)
puts("is OK.");
else
printf("may invite more people, such as %d.\n", index);
}
return 0;
}