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. CF908G New Year and Original Order

    题面 题意翻译 给定$n<=10^{700}$,问$1$到$n$中每个数在各数位排序后得到的数的和.答案$mod\;10^9+7$. 题解 考虑设$f[i][j][k][0/1]$表示前$i$位 ...

  2. 【Menu】 目录索引

    一. 开发语言(25%) 1.Python 2.shell 3.C.C++ 4.java 5.html 二.系统(25%) 1.redhat Linux 2.suse Linux 3.windows ...

  3. C#简单的四位纯数字验证码

    验证码练手,整型.四位验证码 大体意思就是:四位纯数字验证,只要验证不成功就无限验证 刚开始在纠结怎么让整个过程循环起来,什么循环放到最外层,其实就是一个循环,看来自己的循环练习的还是不够多,不够灵活 ...

  4. vue使用import来引入组件的注意事项

    Vue使用import ... from ...来导入组件,库,变量等.而from后的来源可以是js,vue,json.这个是在webpack.base.conf.js中设置的: module.exp ...

  5. python OptionParser模块使用

    OptionParser是python中用来处理命令行的模块,在我们使用python进行流程化开发中必要的工具 Optparse,它功能强大,而且易于使用,可以方便地生成标准的.符合Unix/Posi ...

  6. Kubernetes服务发现之Service详解

    一.引子 Kubernetes Pod 是有生命周期的,它们可以被创建,也可以被销毁,然后一旦被销毁生命就永远结束.通过ReplicationController 能够动态地创建和销毁Pod(列如,需 ...

  7. 统计学习方法c++实现之八 EM算法与高斯混合模型

    EM算法与高斯混合模型 前言 EM算法是一种用于含有隐变量的概率模型参数的极大似然估计的迭代算法.如果给定的概率模型的变量都是可观测变量,那么给定观测数据后,就可以根据极大似然估计来求出模型的参数,比 ...

  8. LeetCode 刷题笔记 155. 最小栈(Min Stack)

    tag: 栈(stack) 题目描述 设计一个支持 push,pop,top 操作,并能在常数时间内检索到最小元素的栈. push(x) -- 将元素 x 推入栈中. pop() -- 删除栈顶的元素 ...

  9. git解决代码提交冲突

    树冲突文件名修改造成的冲突,称为树冲突.比如,A同事把文件改名为A.C,B同事把同一个文件改名为B.C,那么B同事将这两个commit合并时,会产生冲突.如果最终确定用B同事的文件名,那么解决办法如下 ...

  10. python 网页转pdf

    主要使用的是wkhtmltopdf的Python封装——pdfkit centos环境 安装:Install python-pdfkit pip install pdfkit 安装:Install w ...