当前位置: 首页 > news >正文

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. 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.

 题目大意:为峰会安排休息区,一个理想的安排是邀请这些领导人,每个人互相之间都是直接朋友。给定一套暂定的安排,判断每个区域是否都已准备就绪。抽象一下可以看做有m条边,n个顶点的无向图,给定k次查询,每次查询给出点集中点的数量,以及顶点编号,问这些点是否两两连通,如果不联通输出needs help;如果是的话,是否存在其它顶点加入后仍然保持两两连通,有这样的点的话输出最小的点编号,否则输出OK。

分析:由于点的数量很少,可以直接用暴力的方法检查是否是连通子图,如果是的话再检查是否有其它点加入后仍然连通。

#include<algorithm>
#include <iostream>
#include  <cstdlib>
#include  <cstring>
#include   <string>
#include   <vector>
#include   <cstdio>
#include    <queue>
#include    <stack>
#include    <ctime>
#include    <cmath>
#include      <map>
#include      <set>
#define INF 0xffffffff
#define db1(x) cout<<#x<<"="<<(x)<<endl
#define db2(x,y) cout<<#x<<"="<<(x)<<", "<<#y<<"="<<(y)<<endl
#define db3(x,y,z) cout<<#x<<"="<<(x)<<", "<<#y<<"="<<(y)<<", "<<#z<<"="<<(z)<<endl
#define db4(x,y,z,r) cout<<#x<<"="<<(x)<<", "<<#y<<"="<<(y)<<", "<<#z<<"="<<(z)<<", "<<#r<<"="<<(r)<<endl
#define db5(x,y,z,r,w) cout<<#x<<"="<<(x)<<", "<<#y<<"="<<(y)<<", "<<#z<<"="<<(z)<<", "<<#r<<"="<<(r)<<", "<<#w<<"="<<(w)<<endl
using namespace std;int main(void)
{#ifdef testfreopen("in.txt","r",stdin);//freopen("in.txt","w",stdout);clock_t start=clock();#endif //testint n,m;scanf("%d%d",&n,&m);int num[n+5][n+5];for(int i=0;i<=n;++i)for(int j=0;j<=n;++j)num[i][j]=0;for(int i=0;i<m;++i){int a,b;scanf("%d%d",&a,&b);num[a][b]=num[b][a]=1;}int k;scanf("%d",&k);for(int Case=1;Case<=k;++Case){printf("Area %d ",Case);int cnt,f=1;scanf("%d",&cnt);int ques[cnt+5]={0};for(int i=0;i<cnt;++i){scanf("%d",&ques[i]);if(i&&f){for(int j=0;j<i;++j){if(!num[ques[i]][ques[j]]){f=0;break;}}}}if(!f)printf("needs help.\n");else{int index=1;for(int i=1;i<=n;++i){f=1;index=i;for(int j=0;j<cnt;++j){if(num[i][ques[j]]==0){f=0;break;}}if(f)break;}if(!f)printf("is OK.\n");else printf("may invite more people, such as %d.\n",index);}}#ifdef testclockid_t end=clock();double endtime=(double)(end-start)/CLOCKS_PER_SEC;printf("\n\n\n\n\n");cout<<"Total time:"<<endtime<<"s"<<endl;        //s为单位cout<<"Total time:"<<endtime*1000<<"ms"<<endl;    //ms为单位#endif //testreturn 0;
}

http://www.lryc.cn/news/523229.html

相关文章:

  • AUTOSAR从入门到精通-【自动驾驶】高精地图(四)
  • MySQL8数据库全攻略:版本特性、下载、安装、卸载与管理工具详解
  • 网络安全---CMS指纹信息实战
  • 基于C#实现对象序列化的3种方案
  • 蓝桥杯真题 - 公因数匹配 - 题解
  • 使用 Java 实现基于 DFA 算法的敏感词检测
  • Jenkins-Pipeline简述
  • Linux操作命令之云计算基础命令
  • 【postgres】sqlite格式如何导入postgres数据库
  • 阀井可燃气体监测仪,开启地下管网安全新篇章-旭华智能
  • 《offer 来了:Java 面试核心知识点精讲 -- 原理篇》
  • 搭建一个基于Spring Boot的数码分享网站
  • K210视觉识别模块
  • JAVA:在IDEA引入本地jar包的方法(不读取maven目录jar包)
  • 存在重复元素(217)
  • 聊聊如何实现Android 放大镜效果
  • linux 安装mysql5.6
  • 【Vue3 入门到实战】3. ref 和 reactive区别和适用场景
  • edge浏览器恢复旧版滚动条
  • Flink(十):DataStream API (七) 状态
  • AWTK fscript 中的 输入/出流 扩展函数
  • C# OpenCvSharp 部署3D人脸重建3DDFA-V3
  • 【人工智能】:搭建本地AI服务——Ollama、LobeChat和Go语言的全方位实践指南
  • 数据结构——堆(介绍,堆的基本操作、堆排序)
  • Excel中函数ABS( )的用法
  • 【数据分析】02- A/B 测试:玩转假设检验、t 检验与卡方检验
  • Windows下的C++内存泄漏检测工具Visual Leak Detector (VLD)介绍及使用
  • [苍穹外卖] 1-项目介绍及环境搭建
  • 人物一致性训练测评数据集
  • AI的出现,是否能替代IT从业者?