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. java用户角色权限设计

    实现业务系统中的用户权限管理 B/S系统中的权限比C/S中的更显的重要,C/S系统因为具有特殊的客户端,所以访问用户的权限检测可以通过客户端实现或通过客户端+服务器检测实现,而B/S中,浏览器是每一台 ...

  2. 前端性能调优Gzip Filter

    转自:https://blog.csdn.net/zxk15982106569/article/details/18922613 客户端向web服务器端发出了请求后,通常情况下服务器端会将页面文件和其 ...

  3. mysql/sql server和java之间的数据类型对应关系

    Mysql************************************当前列 ClassName ColumnType DisplaySize TypeName0: java.lang.I ...

  4. 使用AngularJS创建应用的5个框架(转)

    原文地址:http://www.php100.com/html/dujia/2015/0206/8580.html 本文由PHP100中文网编译,转载请看文末的转载要求,谢谢合作! 如果你计划使用An ...

  5. CSS中路径及form表单的用法

    1.什么是路径? 路劲分为三种 1.绝对路径: 从盘符开始,然后依次的往下查找 本地: C:/Users/Administrator/Desktop/0527day01/07.html 服务器的: w ...

  6. c++ isdigit函数

    函数名:isdigit 函数所需头文件:#include<cstdio> 函数格式:isdigit(字符) 函数作用:判断括号内是否为1~9的数字. 例:isdigit(4) 就是true ...

  7. 数学+DP Codeforces Round #304 (Div. 2) D. Soldier and Number Game

    题目传送门 /* 题意:这题就是求b+1到a的因子个数和. 数学+DP:a[i]保存i的最小因子,dp[i] = dp[i/a[i]] +1;再来一个前缀和 */ /***************** ...

  8. 用SpringMVC实现的上传下载

    1.导入相关jar包 commons-fileupload.jar commons-io.jar 2.配置web.xml文件 <?xml version="1.0" enco ...

  9. 403 Frog Jump 青蛙过河

    一只青蛙想要过河. 假定河流被等分为 x 个单元格,并且在每一个单元格内都有可能放有一石子(也有可能没有). 青蛙可以跳上石头,但是不可以跳入水中.给定石子的位置列表(用单元格序号升序表示), 请判定 ...

  10. 《编写可维护的Javascript》学习总结

    第一部分 一.基本规范 1.缩进:一般以四个空格为一个缩进. 2.语句结尾:最好加上分号,因为虽然“自动分号插入(ASI)”机制在没有分号的位置会插入分号,但是ASI规则复杂而且会有特殊情况发生 // ...