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.
whereH
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;
}
相关文章:
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 tenta…...
AUTOSAR从入门到精通-【自动驾驶】高精地图(四)
目录 前言 现状概述 算法原理 高精地图的构成 A.基础地图层 B.几何地图层 C.语义地图层 D.道路连接层 E.先验地图层 F.实时地图数据 高精地图的构建及维护 移动建图系统 高精地图维护 A.地图变换检测 B.地图数据更新 3. 众包建图 3.1 众包建图的优劣势 3.2 众包起源:M…...

MySQL8数据库全攻略:版本特性、下载、安装、卸载与管理工具详解
大家好,我是袁庭新。 MySQL作为企业项目中的主流数据库,其5.x和8.x版本尤为常用。本文将详细介绍MySQL 8.x的特性、下载、安装、服务管理、卸载及管理工具,旨在帮助用户更好地掌握和使用MySQL数据库。 1.MySQL版本及下载 企业项目中使用的…...

网络安全---CMS指纹信息实战
CMS简介 CMS(Content Management System)指的是内容管理系统,如WordPress、Joomla等。CMS系统非常常见,几乎所有大型网站都使用CMS来管理其网站的内容。由于常见CMS的漏洞较多,因此黑客将不断尝试利用这些漏洞攻击CMS…...

基于C#实现对象序列化的3种方案
大家好!我是付工。 在上位机开发过程中,我们可能经常要实现一个数据对象的持久化,将对象保存到具体的文件中,今天给大家介绍常用的3种方案,大家根据实际情况,选择适合的方案。 一、准备工作 在介绍这4种…...
蓝桥杯真题 - 公因数匹配 - 题解
题目链接:https://www.lanqiao.cn/problems/3525/learning/ 个人评价:难度 2 星(满星:5) 前置知识:调和级数 整体思路 题目描述不严谨,没说在无解的情况下要输出什么(比如 n n n …...

使用 Java 实现基于 DFA 算法的敏感词检测
使用 Java 实现基于 DFA 算法的敏感词检测 1. 引言 敏感词检测在内容审核、信息过滤等领域有着广泛的应用。本文将介绍如何使用 DFA(Deterministic Finite Automaton,确定有限状态自动机) 算法,在 Java 中实现高效的敏感词检测。…...

Jenkins-Pipeline简述
一. 什么是Jenkins pipeline: pipeline在jenkins中是一套插件,主要功能在于,将原本独立运行于单个或者多个节点的任务连接起来,实现单个任务难以完成的复杂发布流程。Pipeline的实现方式是一套Groovy DSL,任何发布流程…...

Linux操作命令之云计算基础命令
一、图形化界面/文本模式 ctrlaltF2-6 图形切换到文本 ctrlalt 鼠标跳出虚拟机 ctrlaltF1 文本切换到图形 shift ctrl "" 扩大 ctrl "-" 缩小 shift ctrl "n" 新终端 shift ctrl "t" 新标签 alt 1,…...
【postgres】sqlite格式如何导入postgres数据库
step1 在ubuntu系统安装pgloader(centos系统难以直接通过yum安装,如果源码安装的话,会比较费劲) step2,执行如下python脚本 from pathlib import Path import subprocess dataset_dir Path(/app/sqlite_to_pg/chas…...

阀井可燃气体监测仪,开启地下管网安全新篇章-旭华智能
在城市的脉络中,地下管网犹如隐秘的动脉,支撑着现代生活的运转。而在这庞大网络的关键节点上,阀井扮演着不可或缺的角色。然而,由于其密闭性和复杂性,阀井内部一旦发生可燃气体泄漏,将对公共安全构成严重威…...

《offer 来了:Java 面试核心知识点精讲 -- 原理篇》
在 Java 面试的战场上,只知皮毛可不行,面试官们越来越看重对原理的理解。今天就给大家分享一本能让你在面试中脱颖而出的 “武林秘籍”——《offer 来了:Java 面试核心知识点精讲 -- 原理篇》。 本书详细介绍了Java架构师在BAT和移动互联网公…...

搭建一个基于Spring Boot的数码分享网站
搭建一个基于Spring Boot的数码分享网站可以涵盖多个功能模块,例如用户管理、数码产品分享、评论、点赞、收藏、搜索等。以下是一个简化的步骤指南,帮助你快速搭建一个基础的数码分享平台。 — 1. 项目初始化 使用 Spring Initializr 生成一个Spring …...

K210视觉识别模块
K210视觉识别模块是一款功能强大的AI视觉模块,以下是对其的详细介绍: 一、核心特性 强大的视觉识别功能:K210视觉识别模块支持多种视觉功能,包括但不限于人脸识别、口罩识别、条形码和二维码识别、特征检测、数字识别、颜色识别…...

JAVA:在IDEA引入本地jar包的方法(不读取maven目录jar包)
问题: 有时maven使用的jar包版本是最新版,但项目需要的是旧版本,每次重新install会自动将mavan的jar包覆盖到项目的lib目录中,导致项目报错。 解决: 在IDEA中手动配置该jar包对应的目录。 点击菜单File->Projec…...
存在重复元素(217)
217. 存在重复元素 - 力扣(LeetCode) class Solution { public:bool containsDuplicate(vector<int>& nums) {//stl sortsort(nums.begin(), nums.end());for (int i 0; i < nums.size() - 1; i) {if (nums[i] nums[i1]) {return true;}…...

聊聊如何实现Android 放大镜效果
一、前言 很久没有更新Android 原生技术内容了,前些年一直在做跨端方向开发,最近换工作用重新回到原生技术,又回到了熟悉但有些生疏的环境,真是感慨万分。 近期也是因为准备做地图交互相关的需求,功能非常复杂&#x…...
linux 安装mysql5.6
下载mysql安装包 https://dev.mysql.com/downloads/mysql/5.6.html卸载系统自带的mariadb [rootgpap-prod-3 ~]# rpm -qa| grep mariadb mariadb-libs-5.5.68-1.el7.x86_64 [rootgpap-prod-3 ~]# rpm -e --nodeps mariadb-libs-5.5.68-1.el7.x86_64 warning: /etc/my.cnf sav…...

【Vue3 入门到实战】3. ref 和 reactive区别和适用场景
目录 编辑 1. ref 部分 1.1 ref定义基本数据类型 1.2 ref 定义引用数据类型 2. reactive 函数 3. ref 和 reactive 对比 3.1 原理 3.2 区别 3.3 使用原则 在 Vue 3 中 ref 和 reactive 是用于创建响应式数据的两个核心函数。它们都属于 Composition API 的一部分&…...

edge浏览器恢复旧版滚动条
1、地址栏输入edge://flags 2、搜索Fluent scrollbars.,选择disabled,重启即可...
Python|GIF 解析与构建(5):手搓截屏和帧率控制
目录 Python|GIF 解析与构建(5):手搓截屏和帧率控制 一、引言 二、技术实现:手搓截屏模块 2.1 核心原理 2.2 代码解析:ScreenshotData类 2.2.1 截图函数:capture_screen 三、技术实现&…...
ubuntu搭建nfs服务centos挂载访问
在Ubuntu上设置NFS服务器 在Ubuntu上,你可以使用apt包管理器来安装NFS服务器。打开终端并运行: sudo apt update sudo apt install nfs-kernel-server创建共享目录 创建一个目录用于共享,例如/shared: sudo mkdir /shared sud…...

最新SpringBoot+SpringCloud+Nacos微服务框架分享
文章目录 前言一、服务规划二、架构核心1.cloud的pom2.gateway的异常handler3.gateway的filter4、admin的pom5、admin的登录核心 三、code-helper分享总结 前言 最近有个活蛮赶的,根据Excel列的需求预估的工时直接打骨折,不要问我为什么,主要…...

srs linux
下载编译运行 git clone https:///ossrs/srs.git ./configure --h265on make 编译完成后即可启动SRS # 启动 ./objs/srs -c conf/srs.conf # 查看日志 tail -n 30 -f ./objs/srs.log 开放端口 默认RTMP接收推流端口是1935,SRS管理页面端口是8080,可…...

Springcloud:Eureka 高可用集群搭建实战(服务注册与发现的底层原理与避坑指南)
引言:为什么 Eureka 依然是存量系统的核心? 尽管 Nacos 等新注册中心崛起,但金融、电力等保守行业仍有大量系统运行在 Eureka 上。理解其高可用设计与自我保护机制,是保障分布式系统稳定的必修课。本文将手把手带你搭建生产级 Eur…...
解决本地部署 SmolVLM2 大语言模型运行 flash-attn 报错
出现的问题 安装 flash-attn 会一直卡在 build 那一步或者运行报错 解决办法 是因为你安装的 flash-attn 版本没有对应上,所以报错,到 https://github.com/Dao-AILab/flash-attention/releases 下载对应版本,cu、torch、cp 的版本一定要对…...
【HTML-16】深入理解HTML中的块元素与行内元素
HTML元素根据其显示特性可以分为两大类:块元素(Block-level Elements)和行内元素(Inline Elements)。理解这两者的区别对于构建良好的网页布局至关重要。本文将全面解析这两种元素的特性、区别以及实际应用场景。 1. 块元素(Block-level Elements) 1.1 基本特性 …...
Mobile ALOHA全身模仿学习
一、题目 Mobile ALOHA:通过低成本全身远程操作学习双手移动操作 传统模仿学习(Imitation Learning)缺点:聚焦与桌面操作,缺乏通用任务所需的移动性和灵活性 本论文优点:(1)在ALOHA…...

GruntJS-前端自动化任务运行器从入门到实战
Grunt 完全指南:从入门到实战 一、Grunt 是什么? Grunt是一个基于 Node.js 的前端自动化任务运行器,主要用于自动化执行项目开发中重复性高的任务,例如文件压缩、代码编译、语法检查、单元测试、文件合并等。通过配置简洁的任务…...

基于IDIG-GAN的小样本电机轴承故障诊断
目录 🔍 核心问题 一、IDIG-GAN模型原理 1. 整体架构 2. 核心创新点 (1) 梯度归一化(Gradient Normalization) (2) 判别器梯度间隙正则化(Discriminator Gradient Gap Regularization) (3) 自注意力机制(Self-Attention) 3. 完整损失函数 二…...