PAT 1142 Maximal Clique
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的更多相关文章
- PAT 1142 Maximal Clique[难]
1142 Maximal Clique (25 分) A clique is a subset of vertices of an undirected graph such that every t ...
- [PAT] 1142 Maximal Clique(25 分)
1142 Maximal Clique(25 分) A clique is a subset of vertices of an undirected graph such that every tw ...
- PAT 甲级 1142 Maximal Clique
https://pintia.cn/problem-sets/994805342720868352/problems/994805343979159552 A clique is a subset o ...
- PAT A1142 Maximal Clique (25 分)——图
A clique is a subset of vertices of an undirected graph such that every two distinct vertices in the ...
- 1142. Maximal Clique (25)
A clique is a subset of vertices of an undirected graph such that every two distinct vertices in the ...
- 1142 Maximal Clique
题意:给出一个图,定义这样一个结点子集subset,若subset中的任意两结点不都相邻,则称之为Not a Clique:若subset中的任意两结点都相邻,则称之为Clique:若subset中的 ...
- PAT_A1142#Maximal Clique
Source: PAT A1142 Maximal Clique (25 分) Description: A clique is a subset of vertices of an undirect ...
- A1142. Maximal Clique
A clique is a subset of vertices of an undirected graph such that every two distinct vertices in the ...
- PAT (Advanced Level) 1140~1143:1140模拟 1141模拟 1142暴力 1143 BST+LCA
1140 Look-and-say Sequence(20 分) 题意:观察序列D, D1, D111, D113, D11231, D112213111, ...,显然后一个串是对前一个串每一小段连 ...
随机推荐
- 使用Java实现图像分割
为减少动画制作过程中的IO操作,我们可以使用连续动画来改善动画播放效率.如果我们对图像中的每张小图像单独分割成独立的文件,那么当每次要使用这些小图像的时候,我们都得从文件中读取图像信息. 实际上我们可 ...
- swoole之 swoole_process 应用于TP框架
swoole_process 实现了多进程的管理,多个进程同时进行采集任务, 公司的框架比较low,用的tp框架,结合tp框架实现多进程的采集 这是swoole好的学习资源 https://segme ...
- C#基础 for 穷举、迭代
//循环可以解决的问题类型 //穷举,把所有可能的情况都走一遍,使用if条件筛选出来满足条件的情况. //单位给发了一张150元购物卡, //拿着到超市买三类洗化用品. //洗发水15元,香皂2元,牙 ...
- jQuery实现将div中滚动条滚动到指定位置的方法
1.JS代码: onload = function () { //初始化 scrollToLocation(); }; function scrollToLocation() { var mainCo ...
- 观察者模式(observer)c++实现
1意图 定义对象间的一种一对多的依赖关系,当一个对象的状态发生改变时,所有依赖于它的对象都得到通知并被自动更新. 2别名 依赖(Dependents), 发布-订阅(Publish-Subscribe ...
- Activity的退出和進入效果
看了android的源代码和资源文件,终于明白如何去修改设置Dialog和Activity的进入和退出效果了.设置Dialog首先通过 getWindow()方法获取它的窗口,然后通过getAttri ...
- 内存溢出及Jvm监控工具
内存泄露与内存溢出 内存溢出 out of memory,是指程序在申请内存时,没有足够的内存空间供其使用,出现out of memory. 内存泄露 memory leak,是指程序在申请内存后,无 ...
- LR接口测试---基于http协议之get/post
get请求代码: //=====================get interface======================== 以http状态码方式: //获取返回的HTTP状态码判断请求 ...
- 解决:未能加载文件或程序集“System.Web.Http, Version=5.2.4.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35”或它的某一个依赖项。找到的程序集清单定义与程序集引用不匹配。 (异常来自 HRESULT:0x80131040)
今天发布web API,调用接口报错了:未能加载文件或程序集“System.Web.Http, Version=5.2.4.0, Culture=neutral, PublicKeyToken=31b ...
- java树型结构的数据展现设计
在做一个需求管理的页面时,需求的展现是不限层级树型结构,需求下还可以分拆任务,页面要展现的字段有20多个,而且需求采用通用表单设计,db采用大宽表存储,有一百多个字段.目前数据量不大,第一版采用普通的 ...