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<iostream>
#include<vector>
using namespace std;
int main(){
int nv, ne, k, n;
cin>>nv>>ne;
vector<vector<int>> G(205, vector<int>(205, 0));
for(int i=0; i<ne; i++){
int v1, v2;
cin>>v1>>v2;
G[v1][v2]=G[v2][v1]=1;
}
cin>>k;
for(int i=0; i<k; i++){
bool full=true, clique=true;
cin>>n;
vector<int> vi(n, 0), a(nv+1, 0);
for(int j=0; j<n; j++){
cin>>vi[j];
a[vi[j]]=1;
}
for(int j=0; j<n; j++){
if(clique==false) break;
for(int l=j+1; l<n; l++){
if(G[vi[j]][vi[l]]!=1){
clique=false;
cout<<"Not a Clique"<<endl;
break;
}
}
}
if(clique==false) continue;
for(int j=1; j<=200; j++){
if(a[j]==0){
for(int l=0; l<n; l++){
if(G[vi[l]][j]==0) break;
if(l==n-1) full=false;
}
}
if(!full){
cout<<"Not Maximal"<<endl;
break;
}
}
if(full) cout<<"Yes"<<endl;
}
return 0;
}

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

    https://pintia.cn/problem-sets/994805342720868352/problems/994805343979159552 A clique is a subset o ...

  4. PAT A1142 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 (25)

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

  6. 1142 Maximal Clique

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

  7. PAT_A1142#Maximal Clique

    Source: PAT A1142 Maximal Clique (25 分) Description: A clique is a subset of vertices of an undirect ...

  8. A1142. Maximal Clique

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

  9. PAT (Advanced Level) 1140~1143:1140模拟 1141模拟 1142暴力 1143 BST+LCA

    1140 Look-and-say Sequence(20 分) 题意:观察序列D, D1, D111, D113, D11231, D112213111, ...,显然后一个串是对前一个串每一小段连 ...

随机推荐

  1. centOS封装

    前言 在实际工作中,CentOS的安装需要设置的语言.键盘模式.时区等信息都存在很大程度上的雷同型.并且,安装完成后的一些设置工作也都是一样的.这些工作都可以在安装操作系统的时候自动完成.最终做到,安 ...

  2. 31. ExtJs4回车事件监听

    转自:https://710542316.iteye.com/blog/2148542 监听表单字段事件: Ext使得对用户某个动作的监听特别简单,诸如单击某个元素或者按下某个键盘上的键. 一个经常性 ...

  3. table样式测试总结tr td宽度分析

    题外话:一直以来习惯布局用ul,li样式调整比较方便,不会互相影响出现一些问题,but~现在公司涉及很多表格打印,都是用table写的,好多宽度高度合并啊,组合啊~~~,单元格之间互相影响,有的样式设 ...

  4. bzoj 1619: [Usaco2008 Nov]Guarding the Farm 保卫牧场【bfs】

    不是严格小于是小于等于啊!!!!!不是严格小于是小于等于啊!!!!!不是严格小于是小于等于啊!!!!! 是我看不懂人话还是翻译不说人话= = 把所有格子按值排个序,bfs扩展打标记即可 #includ ...

  5. 【STM32H7教程】第22章 STM32H7的SysTick实现多组软件定时器

    完整教程下载地址:http://forum.armfly.com/forum.php?mod=viewthread&tid=86980 第22章       STM32H7的SysTick实现 ...

  6. centos 安装sysbench

    安装sysbench 下载并且解压 shell> wget https://github.com/akopytov/sysbench/archive/1.0.zip -O "sysbe ...

  7. [C++ STL] 迭代器(iterator)详解

    背景:指针可以用来遍历存储空间连续的数据结构,但是对于存储空间非连续的,就需要寻找一个行为类似指针的类,来对非数组的数据结构进行遍历.因此,我们引入迭代器概念.   一.迭代器(iterator)介绍 ...

  8. 2017青岛网络赛1011 A Cubic number and A Cubic Number

    A Cubic number and A Cubic Number Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 65535/3276 ...

  9. 洛谷 P3437 [POI2006]TET-Tetris 3D

    二维线段树区间更新啊 树套树的外层树,如果是线段树的话一般似乎不能打标记?(毕竟标记不好下传) 然而起码对于这题是可以的...对于外层线段树,每个节点放两个内层线段树dat和setv,分别是得到的值和 ...

  10. 水题 CodeForces 137A Postcards and photos

    题目传送门 /* 水! */ #include <cstdio> #include <cstring> #include <algorithm> using nam ...