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的更多相关文章

  1. PAT 1142 Maximal Clique[难]

    1142 Maximal Clique (25 分) A clique is a subset of vertices of an undirected graph such that every t ...

  2. [PAT] 1142 Maximal Clique(25 分)

    1142 Maximal Clique(25 分) A clique is a subset of vertices of an undirected graph such that every tw ...

  3. PAT 1142 Maximal Clique

    A clique is a subset of vertices of an undirected graph such that every two distinct vertices in the ...

  4. 1142. Maximal Clique (25)

    A clique is a subset of vertices of an undirected graph such that every two distinct vertices in the ...

  5. 1142 Maximal Clique

    题意:给出一个图,定义这样一个结点子集subset,若subset中的任意两结点不都相邻,则称之为Not a Clique:若subset中的任意两结点都相邻,则称之为Clique:若subset中的 ...

  6. PAT甲级目录

    树(23) 备注 1004 Counting Leaves   1020 Tree Traversals   1043 Is It a Binary Search Tree 判断BST,BST的性质 ...

  7. PAT甲级 图 相关题_C++题解

    图 PAT (Advanced Level) Practice 用到图的存储方式,但没有用到图的算法的题目 目录 1122 Hamiltonian Cycle (25) 1126 Eulerian P ...

  8. PAT A1142 Maximal Clique (25 分)——图

    A clique is a subset of vertices of an undirected graph such that every two distinct vertices in the ...

  9. PAT甲级考前整理(2019年3月备考)之三,持续更新中.....

    PAT甲级考前整理一:https://www.cnblogs.com/jlyg/p/7525244.html,主要讲了131题的易错题及坑点 PAT甲级考前整理二:https://www.cnblog ...

随机推荐

  1. 2017-2018-1 20155317 《信息安全系统设计基础》课堂实践——实现mypwd

    2017-2018-1 20155317 <信息安全系统设计基础>课堂实践——实现mypwd 1 . 学习使用pwd 很显然pwd命令的意思是打印出该文件当前的绝对路径 2 . 了解pwd ...

  2. 2017-2018-2 《网络对抗技术》 20155322 Exp 5 MSF基础应用

    [-= 博客目录 =-] 1-实践目标 1.1-实践介绍 1.2-实践内容 1.3-实践要求 2-实践过程 2.1-情报收集 2.2-主动攻击实践-ms08_067 2.3-浏览器攻击实践-many* ...

  3. 【python3】爬取简书评论生成词云

    一.起因: 昨天在简书上看到这么一篇文章<中国的父母,大都有毛病>,看完之后个人是比较认同作者的观点. 不过,翻了下评论,发现评论区争议颇大,基本两极化.好奇,想看看整体的评论是个什么样, ...

  4. Codeforces 912 E.Prime Gift (折半枚举、二分)

    题目链接:Prime Gift 题意: 给出了n(1<=n<=16)个互不相同的质数pi(2<=pi<=100),现在要求第k大个约数全在所给质数集的数.(保证这个数不超过1e ...

  5. 洛咕 P3964 [TJOI2013]松鼠聚会

    有个结论就是把坐标\((x,y)\)变形成\(((x+y)/2,(x-y)/2)\),切比雪夫距离就变成了曼哈顿距离. 所以变换一下坐标直接统计答案即可. // luogu-judger-enable ...

  6. Redis 为什么使用单进程单线程方式也这么快

    Redis 采用的是基于内存的采用的是单进程单线程模型的 KV 数据库,由 C 语言编写.官方提供的数据是可以达到100000+的 qps.这个数据不比采用单进程多线程的同样基于内存的 KV 数据库 ...

  7. async/await工作机制探究--NodeJS

    ES6中的async/await让Promise变得更加简便,通常await处理的链式Promise会包裹在函数中,返回结果仍然是一个Promise对象. 但是当await直接处理链式Promise时 ...

  8. 通过ftp同步服务器文件:遍历文件夹所有文件(含子文件夹、进度条);简单http同步服务器文件实例

    该代码主要实现,指定ftp服务地址,遍历下载该地址下所有文件(含子文件夹下文件),并提供进度条显示:另外附带有通过http地址方式获取服务器文件的简单实例 废话不多说,直接上代码: 1.FTPHelp ...

  9. yum指令常用参数说明

    1.使用YUM查找软件包 命令:yum search 2.列出所有可安装的软件包 命令:yum list 3.列出所有可更新的软件包 命令:yum list updates 4.列出所有已安装的软件包 ...

  10. 关于springcloud的一些问题总结.txt

    @Bean public CorsFilter corsFilter() { final UrlBasedCorsConfigurationSource source = new UrlBasedCo ...