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:

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.

题目大意:为峰会安排休息区,一个理想的安排是邀请这些领导人,每个人互相之间都是直接朋友。给定一套暂定的安排,判断每个区域是否都已准备就绪。输入格式:第一行给一个正整数N,表示峰会的首领数量,以及一个正整数M,表示友谊关系的数量。接下来是M行,每行给出一对互为朋友的领导人的编号。领导人的编号从1到N。然后给出另一个正整数K,接下来是K行暂定的休息区,每行给出一个正整数L,然后是一系列L个不同的领导人编号。一行中所有数字都用空格分隔。输出格式:对于K个休息区的每一个,请按以下格式将您的建议输出在一行中:如果在这个休息区每个人都互相是直接朋友,并且没有朋友漏掉(即没有其他人是这个休息区每个人的直接朋友),就输出Area X is OK.如果在这个休息区每个人都是每个人的直接朋友,但在不破坏理想安排的情况下,可能还会邀请一些其他领导人,就输出Area X may invite more people, such as H. H是可以被邀请的领导人的最小编号。如果该休息区的安排不理想,则输出Area X needs help. 这样主持人可以提供一些特别的服务帮助领导人们互相了解。

分析:二维数组A作为邻接矩阵存储两个人是否是好朋友,如果是u和v好朋友就将数组A[u][v] = A[v][u] = 1;集合temp存储待检查的序列号。先检查所有的人是不是互相都为好朋友,如果不是的话,直接输出needs help。然后,检查剩下的所有人中,是否有人是他们所有人的好朋友、但是没有被邀请的,如果没有,就输出is OK. 否则输出may invite more people, such as f. 其中f为可以被邀请的领导人的最小编号~

#include <iostream>
#include <set>
using namespace std;
int n, m, k, l, u, v, s, e, f, f2, A[201][201];
int main() {cin >> n >> m;for (int i = 0; i < m; i++) {cin >> u >> v;A[u][v] = A[v][u] = 1;}cin >> k;for (int i = 1; i <= k; i++) {f = 0;set<int> temp;cin >> l;for (int j = 0; j < l; j++) {cin >> e;for (auto it : temp) if (!A[e][it]) f = 1;temp.insert(e);}cout << "Area " << i;if (f) {cout << " needs help.\n";} else {for (int i = 1; i <= n; i++) {f2 = 1;if (temp.count(i)) continue;for (auto it : temp) {if (!A[i][it]) {f2 = 0;break;}}if (f2) {f = i;break;}}if (!f) cout << " is OK.\n";else cout << " may invite more people, such as " << f << ".\n"; }}return 0;
}

1166 Summit – PAT甲级真题相关推荐

  1. PAT甲级真题 1018 A+B in Hogwarts--python解法

    PAT甲级真题 1018 A+B in Hogwarts 提交:2638 通过:1559 通过率:59% If you are a fan of Harry Potter, you would kno ...

  2. PAT甲级真题目录(按题型整理)(转自柳神)

    转载自:https://www.liuchuo.net/archives/2502?tdsourcetag=s_pcqq_aiomsg 最短路径 1003. Emergency (25)-PAT甲级真 ...

  3. PAT甲级真题1166

    思路:判断是否为团,是的话看能否加入一个顶点 代码: #include <iostream> #include <cstring> #include <algorithm ...

  4. 【PAT甲级真题整理五】1121~1155

    终于考完了qaq把最后一堆也整理出来了 目录 1121 Damn Single(25)set.map的使用 1122 Hamiltonian Cycle(25)哈密顿回路 1123 Is It a C ...

  5. PAT甲级真题 1011 World Cup Betting (20分) C++实现

    题目 With the 2010 FIFA World Cup running, football fans the world over were becoming increasingly exc ...

  6. 1131. Subway Map (30)-PAT甲级真题 (DFS or 堆优化dij or SPFA)

    题意 给出地铁线路数n,分别给出每条线的站点数m,再依次列出站点id.然后询问k次从启点sv到终点ev的最短路径,如果最短路径相同,要求换乘最少的路径.最后按条件输出. 思路 1.用unordered ...

  7. 「PAT甲级真题解析」Advanced Level 1009 Product of Polynomials

    PAT (Advanced Level) Practice 1009 Product of Polynomials 如果对你有帮助,要点个赞让我知道喔~ 文章目录 问题分析 完整步骤描述 伪代码描述 ...

  8. 【PAT甲级真题整理三】1061~1090

    目录 1061 Dating(20)字符串处理 1062 Talent and Virtue(25)排序 1063 Set Similarity(25)set的使用 1064 Complete Bin ...

  9. 1040. Longest Symmetric String (25)-PAT甲级真题

    Given a string, you are supposed to output the length of the longest symmetric sub-string. For examp ...

最新文章

  1. seo说_百度指数看世间沉浮_如何快速排名-互点快速排名_网站关键词排名常见问题 - 搜狗快速排名...
  2. C++ 生成洛伦兹的蝴蝶
  3. php 10进制位数保持,php 任意进制的数转换成10进制功能实例
  4. getline函数(精华版)
  5. 计算机无法进系统咋办,详解电脑无法进入系统怎么办
  6. XShell提示Connection closed by foreign host的问题 和 路由器分配IP的规则
  7. WinRAR加密压缩冒充GlobeImposter勒索病毒 安全专家轻松解密
  8. 场地测量的方法和程序_施工测量方案
  9. Qt 之 QQ系统表情(二)
  10. android 看图片tv版,易图浏览_易图浏览TV版APK下载_电视版 for 安卓TV_ZNDS软件
  11. 计算机小高考要点,小高考的复习计划
  12. syslinux和grub引导linux,syslinux引导GRUB4DOS
  13. Android 9.0 蓝牙电话BluetoothHeadsetClient
  14. php 问号乱码,如何解决php问号乱码的问题
  15. 字符串之重复字符统计
  16. HHS整合(Struts2+Spring+Hibernate)
  17. 尤大大(尤雨溪)的年度总结、预期
  18. 【渝粤教育】国家开放大学2018年秋季 7179-22T文献检索 参考试题
  19. 抖音巨量千川是什么?和飞瓜智投有什么不同?后者功能更强大!
  20. 写给20年后的自己:免费的午餐最贵

热门文章

  1. ubuntu 安装 Qt5
  2. C++ MFC (一)
  3. centos 计算器_在Linux命令行中使用计算器的5个命令详解
  4. socket.io 工具
  5. 分贝测试软件哪个好 家庭影院,家庭影院DIY攻略 攻略篇 – 5.2 音频解码能力
  6. 商城源码分享、几十个PHP商城源码,全部分享
  7. QT网络编程——TCP服务器和客户端通信
  8. 大学生可以选择加盟零食店么
  9. Uml 理解Rational Rose软件中四种视图和Uml 9类图之间的关系
  10. win10非系统盘的数据迁移