散列
1. 原文
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. where H 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:
1 | 8 10 |
Sample Output:
1 | Area 1 is OK. |
2. 解析思路
8个峰会代表人,10个好友组
安排的圆桌会议中
- 如果所有人都是直接好友,并且加一个代表人a,a跟圆桌内的所有人并不是直接好友,则当前圆桌是完美的
- 可以加一个a,跟圆桌内的所有人都是直接好友,该圆桌可以增加人数
- 圆桌内并不是好友,需要调整
用 fre[a*maxn+b]=1 代表a和b是好友
3. 代码
1 |
|