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接口和抽象类的特点

    接口的特点: 1:接口不可实例化,可结合多态进行使用(接口 对象=new 对象()) 2:接口里的成员属性全部是以 public(公开).static(静态).final(最终) 修饰符修饰 3:接口 ...

  2. bzoj 2015: [Usaco2010 Feb]Chocolate Giving【spfa】

    因为是双向边,所以相当于两条到1的最短路和,先跑spfa然后直接处理询问即可 #include<iostream> #include<cstdio> #include<q ...

  3. [Swift通天遁地]二、表格表单-(1)创建自定义的UITableViewCell(单元格类)

    ★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★➤微信公众号:山青咏芝(shanqingyongzhi)➤博客园地址:山青咏芝(https://www.cnblogs. ...

  4. org.apache.poi.hssf.util.Region

    从POI 3.18开始被Deprecated,在3.20版本中被移除了,所以3.20以前的都有 为了避免这个问题,用CellRangeAddress代替Region,其用法相同

  5. Redis集群创建和配置

    1.检查GCC是否安装,可以看看版本号 gcc -v 安装命令:yum install gcc-c++ 2.安装Ruby和Rubygems 如果有网的话,则通过yum命令进行安装,自动将关联的依赖包全 ...

  6. 【SPOJ-GCDEX】GCD Extreme(欧拉函数)

    题目: SPOJ-GCDEX (洛谷 Remote Judge) 分析: 求: \[\sum_{i=1}^{n}\sum_{j=i+1}^{n}gcd(i,j)\] 这道题给同届新生讲过,由于种种原因 ...

  7. Android 性能优化(24)*性能工具之「Traceview,dmtracedump」Profiling with Traceview and dmtracedump :记录并查看函数调用栈*

    Profiling with Traceview and dmtracedump In this document Traceview Layout         Traceview工具界面介绍 T ...

  8. JS获取到时间转换成字符串类型

    JS获取到时间格式为:/Date(1479279579047)/ 提供一个函数可将其转换为“yyyy-MM-dd”和“yyyy-MM-dd hh:mm:ss” //时间日期转换成string func ...

  9. 简单js图片点击向左滚动

    <style> .b_left{width:50px;height:75px;float:left;background:url(img/left_right.png) no-repeat ...

  10. scla-基础-函数-元组(0)

    //元组 class Demo2 extends TestCase { def test_create_^^(){ val yuana = (1,true,1.2,"c",&quo ...