PAT 甲级 1142 Maximal Clique
https://pintia.cn/problem-sets/994805342720868352/problems/994805343979159552
A clique is a subset of vertices of an undirected graph such that every two distinct vertices in the clique are adjacent. A maximal clique is a clique that cannot be extended by including one more adjacent vertex. (Quoted from https://en.wikipedia.org/wiki/Clique_(graph_theory))
Now it is your job to judge if a given subset of vertices can form a maximal clique.
Input Specification:
Each input file contains one test case. For each case, the first line gives two positive integers Nv (≤ 200), the number of vertices in the graph, and Ne, the number of undirected edges. Then Ne lines follow, each gives a pair of vertices of an edge. The vertices are numbered from 1 to Nv.
After the graph, there is another positive integer M (≤ 100). Then M lines of query follow, each first gives a positive number K (≤ Nv), then followed by a sequence of K distinct vertices. All the numbers in a line are separated by a space.
Output Specification:
For each of the M queries, print in a line Yes if the given subset of vertices can form a maximal clique; or if it is a clique but not a maximal clique, print Not Maximal; or if it is not a clique at all, print Not a Clique.
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
3 4 3 6
3 3 2 1
Sample Output:
Yes
Yes
Yes
Yes
Not Maximal
Not a Clique
代码:
#include <bits/stdc++.h>
using namespace std; int N, M, K;
int mp[220][220];
int vis[220]; int main() {
scanf("%d%d", &N, &M);
memset(mp, 0, sizeof(mp));
while(M --) {
int a, b;
scanf("%d%d", &a, &b);
mp[a][b] = mp[b][a] = 1;
}
scanf("%d", &K);
while(K --) {
int T;
vector<int> v;
memset(vis, 0, sizeof(vis));
scanf("%d", &T);
v.resize(T);
for(int i = 0; i < T; i ++) {
scanf("%d", &v[i]);
vis[v[i]] = 1;
} bool isclique = true;
for(int i = 0; i < T - 1; i ++) {
for(int j = i + 1; j < T; j ++) {
if(mp[v[i]][v[j]] == 0) {
isclique = false;
printf("Not a Clique\n");
break;
}
}
if(!isclique) break;
} if(!isclique) continue; bool ismax = true;
for(int i = 1; i <= N; i ++) {
if(vis[i] == 0) {
for(int j = 0; j < T; j ++) {
if(mp[v[j]][i] == 0) break;
if(j == T - 1) ismax = false;
}
}
if(!ismax) {
printf("Not Maximal\n");
break;
}
}
if(ismax) printf("Yes\n");
}
return 0;
}
简单图论
FHFHFH
PAT 甲级 1142 Maximal Clique的更多相关文章
- PAT 1142 Maximal Clique[难]
1142 Maximal Clique (25 分) A clique is a subset of vertices of an undirected graph such that every t ...
- [PAT] 1142 Maximal Clique(25 分)
1142 Maximal Clique(25 分) A clique is a subset of vertices of an undirected graph such that every tw ...
- PAT 1142 Maximal Clique
A clique is a subset of vertices of an undirected graph such that every two distinct vertices in the ...
- 1142. Maximal Clique (25)
A clique is a subset of vertices of an undirected graph such that every two distinct vertices in the ...
- 1142 Maximal Clique
题意:给出一个图,定义这样一个结点子集subset,若subset中的任意两结点不都相邻,则称之为Not a Clique:若subset中的任意两结点都相邻,则称之为Clique:若subset中的 ...
- PAT甲级目录
树(23) 备注 1004 Counting Leaves 1020 Tree Traversals 1043 Is It a Binary Search Tree 判断BST,BST的性质 ...
- PAT甲级 图 相关题_C++题解
图 PAT (Advanced Level) Practice 用到图的存储方式,但没有用到图的算法的题目 目录 1122 Hamiltonian Cycle (25) 1126 Eulerian P ...
- PAT A1142 Maximal Clique (25 分)——图
A clique is a subset of vertices of an undirected graph such that every two distinct vertices in the ...
- PAT甲级考前整理(2019年3月备考)之三,持续更新中.....
PAT甲级考前整理一:https://www.cnblogs.com/jlyg/p/7525244.html,主要讲了131题的易错题及坑点 PAT甲级考前整理二:https://www.cnblog ...
随机推荐
- Kubernetes学习之路(十二)之Pod控制器--ReplicaSet、Deployment
一.Pod控制器及其功用 Pod控制器是用于实现管理pod的中间层,确保pod资源符合预期的状态,pod的资源出现故障时,会尝试 进行重启,当根据重启策略无效,则会重新新建pod的资源. pod控制器 ...
- 为什么java代码中要避免多层深度for循环嵌套
在开发中,一直强调代码的整洁和可读性.之前对于使用多层嵌套for循环,一直以为只是对代码可读性和逻辑梳理有影响.可能对性能也有影响,但是一直不知道对性能影响在哪.最近在看虚拟机方面的书,感觉有一个点应 ...
- 第一道防线__SpringMVC配置拦截器
这几天在公司自己开发一个小系统,但是系统的安全性也得考虑,起初没注意,赶急就光关心业务逻辑和实现效果.最后老大一出手,就把最严重的问题指出来了,他说你这根本没安全性可言,于是我试着将公司使用的spri ...
- python的类和对象2(self参数)
python的类和对象2(self参数) 1.python里面对象的方法都会有self参数,它就相当于C++里面的this指针:绑定方法,据说有了这个参数,Python 再也不会傻傻分不清是哪个对象在 ...
- 《Redis设计与实现》阅读笔记(二)--简单动态字符串
简单动态字符串 Redis只在一些无需对字符串进行修改的地方使用C字符串,大部分时候使用简单动态字符串(simple dynamic string, SDS),字符串的抽象类型.二进制安全,可以存放任 ...
- 如何用Python为你的邮箱加油?还有这种操作!
我来介绍一下我是如何使用 Python 来节省成本的. 我最近在开一辆烧 93 号汽油的车子.根据汽车制造商的说法,它只需要加 91 号汽油就可以了.然而,在美国只能买到 87 号.89 号.93 号 ...
- Python遗传算法工具箱DEAP框架分析
本文主要介绍python遗传算法工具箱DEAP的实现.先介绍deap的如何使用,再深入介绍deap的框架实现,以及遗传算法的各种实现算法. 代码可以参考 https://github.com/suma ...
- 高可用OpenStack(Queen版)集群-14.Openstack集成Ceph准备
参考文档: Install-guide:https://docs.openstack.org/install-guide/ OpenStack High Availability Guide:http ...
- 2019 年软件开发人员必学的编程语言 Top 3
AI 前线导读:这篇文章将探讨编程语言世界的现在和未来,这些语言让新一代软件开发者成为这个数字世界的关键参与者,他们让这个世界变得更健壮.连接更加紧密和更有意义.开发者要想在 2019 年脱颖而出,这 ...
- 学习笔记 | Github
Github教程 \(Github\)是个好东西QwQ 存代码不用U盘爸爸妈妈再也不用担心我的U盘弄丢没有备份啦! 创建github账号 创建仓库 输入命令 git clone https://git ...