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

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 test
    freopen("in.txt","r",stdin);
    //freopen("in.txt","w",stdout);
    clock_t start=clock();
    #endif //test

    int 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 test
    clockid_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 //test
    return 0;
}


http://www.kler.cn/a/510470.html

相关文章:

  • openharmony应用开发快速入门
  • ESP8266-01S、手机、STM32连接
  • 数据结构漫游记:动态实现栈(stack)
  • 什么是长连接?Netty如何设置进行长连接?
  • SQL ON与WHERE区别
  • web worker 前端多线程一、
  • web前端2--标签
  • C# OpenCV机器视觉:常用滤波算法
  • ASP.NET Core 实战:JWT 身份验证
  • mysql官方文档翻译02-一致性非锁定读与一致性锁定读
  • k8s 容器反复重启
  • 配置管理与动态调整:ShardingSphere 的配置方式与实时调整能力
  • 使用pytorch从头实现一个vit
  • 大数据相关组件介绍
  • 第148场双周赛:循环数组中相邻元素的最大差值、将数组变相同的最小代价、最长特殊路径、所有安放棋子方案的曼哈顿距离
  • 第1章:Python TDD基础与乘法功能测试
  • 数据库高可用方案-09-数据库的灾难恢复演练
  • 【configparser.NoSectionError: No section: ‘versioneer‘】
  • 第3章:Python TDD更新测试用例测试Dollar类
  • 企业级NoSQL数据库Redis
  • 2025年1月19日(振动控制研究历史)
  • 使用通用预训练范式为 3D 基础模型铺平道路
  • Syncthing在ubuntu下的安装使用
  • AUTOSAR从入门到精通-自动驾驶测试技术
  • 三天急速通关Java基础知识:Day1 基本语法
  • c# 设置Regex Multiline无效问题