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.

代码如下:

#include<iostream>
#include<vector>
using namespace std;vector<vector<int>> edge(250, vector<int>(250, 0));int main() {int n, m;cin >> n >> m;//n个节点m条边for (int i = 0; i < m; i++) {int x, y;cin >> x >> y;edge[x][y] = edge[y][x] = 1;//建立图的连接}int k;cin >> k;for (int i = 1; i <= k; i++) {//查询的记录个数int l;//每个area的点的个数cin >> l;vector<int> v(l);for (int j = 0; j < l; j++)cin >> v[j];bool flag1 = true;for (int j = 0; j < l; j++) {for (int k = j + 1; k < l; k++) {//cout << v[j] << " " << v[k] << " " << edge[v[j]][v[k]] << endl;if (edge[v[j]][v[k]] == 0) {//两点无边,即没关系flag1 = false;break;}}if (flag1 == false) break;//已经不是理想安排了,直接break}bool flag2 = false;int minn = -1;for (int j = 1; j <= n; j++) {//遍历所有节点int k;for (k = 0; k < l; k++) {if (j == v[k]) break;//该点已经在area中,直接breakif (j != v[k] && edge[j][v[k]] == 0) break;//不在area中,但是与area中的当前点没有边,所以不符合,直接break}if (k == l) {//没有通过break退出,说明所有节点遍历完了,既符合不在area中,又与area中已有的所有节点有边,可以插入安排中flag2 = true;minn = j;//由于节点是从序号从小到大遍历的,而插入节点要输出序号最小的,所以找到的即符合要求break;}}if (flag1 == false) printf("Area %d needs help.\n", i);else if (flag2) printf("Area %d may invite more people, such as %d.\n", i, minn);else printf("Area %d is OK.\n", i);}
}

运行结果如下:

A1166 Summit(25分)PAT甲级 (Advanced Level) Practice(C++)满分题解【图】相关推荐

  1. A1124 Raffle for Weibo Followers(20分)PAT 甲级(Advanced Level) Practice(C++)满分题解【map】

    John got a full mark on PAT. He was so happy that he decided to hold a raffle(抽奖) for his followers ...

  2. PAT甲级(Advanced Level)真题--1046 Sharing

    PAT甲级(Advanced Level)真题–1046 Sharing 通过:648 提交:1138 通过率:56% To store English words, one method is to ...

  3. PAT甲级(Advanced Level)真题-- 1062 To Buy or Not to Buy

    PAT甲级(Advanced Level)真题-- 1062 To Buy or Not to Buy 通过:643 提交:1220 通过率:52% Eva would like to make a ...

  4. 1166 Summit (25 分) PAT

    A summit (峰会) is a meeting of heads of state or government. Arranging the rest areas for the summit ...

  5. PAT (Advanced Level) Practice 1043 Is It a Binary Search Tree (25 分) 凌宸1642

    PAT (Advanced Level) Practice 1043 Is It a Binary Search Tree (25 分) 凌宸1642 题目描述: A Binary Search Tr ...

  6. 19年冬季第二题 PAT甲级 1166 Summit (25分)

    7-3 Summit (25分) A summit (峰会) is a meeting of heads of state or government. Arranging the rest area ...

  7. PAT (Advanced Level) Practice 1011 World Cup Betting (20 分) 凌宸1642

    PAT (Advanced Level) Practice 1011 World Cup Betting (20 分) 凌宸1642 题目描述: With the 2010 FIFA World Cu ...

  8. PAT (Advanced Level) Practice 题解代码 - II (1051-1100)

    PAT PAT (Advanced Level) Practice - II(1051-1100) -------------------------------------------------- ...

  9. 1085 PAT单位排行 (25分)-PAT乙级真题-C++实现

    1085 PAT单位排行 (25分)-PAT乙级真题-C++实现 题目描述: 每次 PAT 考试结束后,考试中心都会发布一个考生单位排行榜.本题就请你实现这个功能. 输入格式: 输入第一行给出一个正整 ...

最新文章

  1. js array push 添加内容
  2. nginx四层端口转发
  3. 全球及中国生物质能利用产业现状调研及十四五建设布局规划报告2021-2027年
  4. 使用Azure应用服务本地验证安卓脸书
  5. login.php静态页面的设计,ps+div+css打造蓝色后台--login页面设计
  6. SQLite Update 语句(http://www.w3cschool.cc/sqlite/sqlite-update.html)
  7. matlabapp窗口图像_matlab – 如何自定义App Designer图形的背景?
  8. HTML+CSS+JS实现 ❤️酷炫的时光隧道旅行动特效❤️
  9. linux 7防火墙删除端口号,centos 7 firewall(防火墙)开放端口/删除端口/查看端口
  10. vscode-textlive-paper学习记录
  11. 路由器OpenWRT、LEDE、潘多拉、华硕、梅林、老毛子系统区别和特点
  12. python写出租车计费系统_关于使用Python——写出租车计费系统
  13. NetApp 存储阵列 AFF A 系列——可提供屡获殊荣的速度和响应能力,满足性能敏感性工作负载的需求
  14. 怎样训练左右手协调_吉他,左右手的协调,练习的方法原来这么简单!
  15. 计算机软件类自然科学基金标书,国家自然科学基金标书撰写——体会6(转发仅供参考)...
  16. vscode 使用beautify插件格式化.vue文件
  17. 2023秋招大厂经典面试题及答案整理归纳(201-220)校招必看
  18. matlab拉氏变换求解转移矩阵eAt
  19. 阿里云能做棋牌服务器吗?
  20. 2022.10.9 英语背诵

热门文章

  1. springboot 4大默认容器、指定运行容器
  2. (烦得要死)删除重复字符
  3. 小程序switch内部加上文字_还愿师游戏小程序:这个女性向文字游戏有点意思!游戏结局居然......
  4. 软件开发框架(更新中)
  5. DOM Invader | DOMXSS挖掘助手
  6. 如何彻底删除word、excel中最近使用的文档
  7. 【LeetCode 剑指offer刷题】动态规划与贪婪法题3:剑指Offer-46:把数字翻译成字符串
  8. python学生信息管理系统策划文档
  9. linux查看本机速度命令,Linux命令(20)查看当前网速
  10. Android 代码强制启动GPU渲染