当前位置:网站首页>PAT甲级真题1166
PAT甲级真题1166
2022-07-03 07:00:00 【Ray.C.L】

思路:判断是否为团,是的话看能否加入一个顶点
代码:
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
const int N = 300;
bool st[N];
int g[N][N];
int main()
{
int n,m;
scanf("%d%d", &n, &m);
while (m -- ){
int x,y;
scanf("%d%d", &x, &y);
g[x][y] = g[y][x] = true;
}
scanf("%d", &m);
for(int t = 1; t <= m; t++){
int cnt ;
memset(st, 0, sizeof st);
scanf("%d", &cnt);
while(cnt-- ){
int x;
scanf("%d", &x);
st[x] = true;
}
bool is_clique = true;
for(int i = 1; i <= n; i++)
for(int j = i + 1; j <= n; j++)
if(st[i]&&st[j]&&!g[i][j])
is_clique = false;
if(!is_clique){
printf("Area %d needs help.\n",t);
}else{
int id = 0;
for(int i = 1; i <= n; i++){
if(!st[i]){
bool is_join = true;
for(int j = 1; j <= n; j++)
if(st[j]&&!g[i][j]){
is_join = false;
break;
}
if(is_join){
id = i;
break;
}
}
}
if(id) printf("Area %d may invite more people, such as %d.\n", t, id);
else printf("Area %d is OK.\n", t);
}
}
}
边栏推荐
猜你喜欢

熊市里的大机构压力倍增,灰度、Tether、微策略等巨鲸会不会成为'巨雷'?

The pressure of large institutions in the bear market has doubled. Will the giant whales such as gray scale, tether and micro strategy become 'giant thunder'?

How to specify the execution order for multiple global exception handling classes

Journal quotidien des questions (11)

Dbnet: real time scene text detection with differentiable binarization

Win 10 find the port and close the port

深度学习参数初始化(一)Xavier初始化 含代码

(翻译)异步编程:Async/Await在ASP.NET中的介绍

These two mosquito repellent ingredients are harmful to babies. Families with babies should pay attention to choosing mosquito repellent products

Winter vacation work of software engineering practice
随机推荐
MySQL syntax (basic)
The 10000 hour rule won't make you a master programmer, but at least it's a good starting point
[classes and objects] explain classes and objects in simple terms
VMware virtual machine C disk expansion
Software testing learning - day 3
How does the insurance company check hypertension?
UTC时间、GMT时间、CST时间
The essence of interview
每日刷题记录 (十一)
服务器如何设置多界面和装IIS呢?甜甜给你解答!
[untitled]
CentOS switches and installs mysql5.7 and mysql8.0
Class and object summary
[attribute comparison] defer and async
Tool class static method calls @autowired injected service
Climb movie paradise 2021 hot
Application scenarios of Catalan number
Stream stream
[Code] if (list! = null & list. Size() > 0) optimization, set empty judgment implementation method
How to migrate or replicate VMware virtual machine systems