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 <cstring>
#include <algorithm>using namespace std;const int N = 210;int vers[N];
bool g[N][N], st[N];
int n, m, k;bool check_friends(int l)
{for (int i = 0; i < l; i ++ )for (int j = 0; j < i; j ++ )if (!g[vers[i]][vers[j]])return false;return true;
}bool check_full_friends(int l, int& t)
{memset(st, 0, sizeof st);for (int i = 0; i < l; i ++ )st[vers[i]] = true;for (int i = 1; i <= n; i ++ )if (!st[i]){bool success = true;for (int j = 0; j < l; j ++ )if (!g[i][vers[j]]){success = false;break;}if (success) {t = i;return false;}}return true;
}int main()
{scanf("%d %d", &n, &m);for(int i = 1; i <= m; i ++ ){int a, b;scanf("%d %d", &a, &b);g[a][b] = g[b][a] = true;}scanf("%d", &k);for(int i = 1; i <= k; i ++ ){int l;scanf("%d", &l);for(int i = 0; i < l; i ++ ) scanf("%d", &vers[i]);if(check_friends(l)){int t = 1;if(check_full_friends(l, t)) printf("Area %d is OK.\n", i);else printf("Area %d may invite more people, such as %d.\n", i, t);}else printf("Area %d needs help.\n", i);}
}

1166 Summit (25 分) PAT相关推荐

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

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

  2. PAT (Advanced Level) Practice 1166 Summit (25 分)

    题目 因为只是判断是否是直接相连,所以觉得直接用暴力模拟,而且数据范围也很小.果然,许久不练题,A题的效率都下降了.不过,练题真的是打发时间的好途径. #include <bits/stdc++ ...

  3. PAT甲级——1166 Summit (25 分)

    思路: 模拟,用两位vector表示edge相连关系 然后,看是否两两相连和是否有其他点与其都相连 src // 不需要并查 #include<bits/stdc++.h> using n ...

  4. 1166 Summit (25 point(s)) PAT甲级

    1166 Summit (25 point(s)) 题目 A summit (峰会) is a meeting of heads of state or government. Arranging t ...

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

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

  6. 7-3 Summit (25分)

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

  7. 5-35 城市间紧急救援 (25分) pat 数据结构

    题目连接 https://pta.patest.cn/pta/test/15/exam/4/question/862 5-35 城市间紧急救援   (25分) 作为一个城市的应急救援队伍的负责人,你有 ...

  8. PAT 甲级1166(图)Summit (25分)

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

  9. PAT A1162 7-3 Summit (25分)

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

最新文章

  1. 数学家的亿万商业王国:先后创建“验证码”和“多邻国”,20岁就被盖茨亲自挖去微软!...
  2. 【云周刊】第132期:走近40+世界级AI专家!第三届中国人工智能大会资料分享...
  3. 马克思关于劳动的八大金句
  4. react学习(41)----react中的jsx简介
  5. 图像分类_PyTorch图像数据分类
  6. golang基本语法——变量使用详解
  7. C++ 循环for 引用 for(string : )
  8. Common Digester学习
  9. [译] PWA 实战:Tinder 的性能优化之道
  10. 接口测试工具设计与实现
  11. 《解读基金》 基金中统计指标含义-平均回报、标准差、夏普比率、阿尔法系数、贝塔系数、R平方
  12. 【转】Photoshop 用户名.组织或序列号丢失或无效.应用程序无法继续.
  13. linux远程利用漏洞CVE-2016-4484 93次空密码重试就可以获得root权限 影响大多数Linux版本...
  14. html5游戏编程核心技术与实战目录
  15. PJSIP 下载和编译
  16. 计算机二级office考试题库操作题,计算机二级考试MSOffice考试题库ppt操作题附答案...
  17. java8 .stream().anyMatch / allMatch / noneMatch用法
  18. 测试用例-------纸杯
  19. 如何在kubernetes中使用共享GPU资源
  20. mysql豹_MySQL创建数据库与创建用户以及授权 小帅豹

热门文章

  1. 2300套php网站源码模板 完整后台程序 整站带数据,ID41:建材自适应PC手机平板微信Seo结构送2300套PHP整站源码...
  2. springboot 4大默认容器、指定运行容器
  3. 新零售新连锁未来的发展趋势
  4. 楼上漏水,楼下被淹,如何维权
  5. Esri美国个人许可购买指南
  6. html5小游戏主要用的js,用js+HTML5实现的小游戏-- 捕鱼达人游戏
  7. SharePoint Designer 2007 IS NOW FREE
  8. win7蓝屏0x000000f4修复_关于近期财务电脑蓝屏的处理和预防方法,必看!
  9. 前端中英文切换,复制所有页面 / i18n
  10. ZZULIOJ:1006 求等差数列的和