当前位置:网站首页>PAT甲级 1142 最大团
PAT甲级 1142 最大团
2022-06-12 16:38:00 【键盘奏鸣曲】
在一个无向图中,如果一个顶点子集满足子集内的任意两个不同顶点之间都是相连的,那么这个顶点子集就被称为一个团。
如果一个团不能通过加入某个新的顶点来扩展成一个更大的团,那么该团就被称为最大团。
现在,你需要判断给定顶点子集能否构成一个最大团。
输入格式
第一行包含两个整数 Nv 和 Ne,分别表示无向图中点和边的数量。接下来 Ne 行,每行包含两个整数 a,b,表示点 a 和点 b 之间存在一条边。
所有点的编号从 1 到 Nv。
再一行,包含整数 M,表示询问次数。
接下来 M 行,每行描述一个询问顶点子集,首先包含一个整数 K,表示子集包含点的数量,然后包含 K 个整数,表示 K 个不同顶点的编号。
一行中所有数字之间用一个空格隔开。
输出格式
每组询问在一行中输出一个结论。如果给定子集是最大团,则输出 Yes,如果是一个团,但不是最大团,则输出 Not Maximal,如果根本不是团,则输出 Not a Clique。
数据范围
1≤Nv≤200,
1≤Ne≤Nv(Nv−1)2,
1≤M≤100,
1≤K≤Nv
输入样例:
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
3 4 3 6
3 3 2 1
输出样例:
Yes
Yes
Yes
Yes
Not Maximal
Not a Clique
我的解法:
#include <bits/stdc++.h>
using namespace std;
const int N = 210;
bool g[N][N];
int nodes[N];
int n, m;
int main(){
cin >> n >> m;
while(m -- ){
int a, b;
cin >> a >> b;
g[a][b] = g[b][a] = true;
}
int k;
cin >> k;
while(k --){
int num;
cin >> num;
for(int i = 1; i <= num; i ++ ){
cin >> nodes[i];
}
bool flag = true;
for(int i = 1; i <= num; i ++ ){
if(!flag) break;
for(int j = i + 1; j <= num; j ++ ){
if(!g[nodes[i]][nodes[j]]){
flag = false;
break;
}
}
}
if(flag){
bool is_max = true;
for(int i = 1; i <= n; i ++ ){
bool flag2 = true;
for(int j = 1; j <= num; j ++ ){
if(!g[i][nodes[j]]) flag2 = false;
}
if(flag2){
is_max = false;
break;
}
}
if(is_max) puts("Yes");
else puts("Not Maximal");
}
else{
puts("Not a Clique");
}
}
return 0;
}边栏推荐
- Differences between SQL and NoSQL of mongodb series
- Loading shellcode in C and go languages
- SwinTransformer网络架构
- ISCC-2022 部分wp
- Canvas image processing (Part 1)
- 【研究】英文论文阅读——英语poor的研究人员的福利
- Which colleges are particularly easy to enter?
- Leetcode 2190. 数组中紧跟 key 之后出现最频繁的数字(可以,一次过)
- JS écoute si l'utilisateur allume le focus de l'écran
- Iscc-2022 part WP
猜你喜欢

SwinTransformer网络架构

How to base on CCS_ V11 new tms320f28035 project

如何基于CCS_V11新建TMS320F28035的工程

双写一致性问题
![[research] reading English papers -- the welfare of researchers in English poor](/img/8a/671e6cb6a3f4e3b84ea0795dc5a365.png)
[research] reading English papers -- the welfare of researchers in English poor

Cookie 和 Session

su直接切换到超级管理员模式,这样很多报错都可以避免了

acwing 800. Target and of array elements

QCustomplot笔记(一)之QCustomplot添加数据以及曲线

Overview of webrtc's audio network Countermeasures
随机推荐
[MySQL] internal connection, external connection and self connection (detailed explanation)
MySQL interview arrangement
Learning notes of MySQL series by database and table
\Begin{algorithm} notes
Leetcode 2194. Cellules dans une plage dans un tableau Excel (OK, résolu)
uabntu的sudo
JS écoute si l'utilisateur allume le focus de l'écran
Probation period and overtime compensation -- knowledge before and after entering the factory labor law
Object. Keys traverses an object
std::set compare
Demande de doctorat | xinchao Wang, Université nationale de Singapour
【BSP视频教程】BSP视频教程第17期:单片机bootloader专题,启动,跳转配置和调试下载的各种用法(2022-06-10)
Why is your next computer a computer? Explore different remote operations
Doctor application | National University of Singapore, Xinchao Wang, teacher recruitment, doctor / postdoctoral candidate in the direction of graph neural network
CVPR 2022 | meta learning performance in image regression task
Information outline recording tool: omnioutliner 5 Pro Chinese version
[fishing artifact] UI library second change lowcode tool -- List part (I) design and Implementation
Servlet API
博士申請 | 新加坡國立大學Xinchao Wang老師招收圖神經網絡方向博士/博後
Servlet API