A1142. 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 cliqueis 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<algorithm>
#include<cstdio>
using namespace std;
int G[][] = {};
int Nv, Ne;
int seq[], hashTB[];
int main(){
scanf("%d%d", &Nv, &Ne);
for(int i = ; i < Ne; i++){
int v1, v2;
scanf("%d%d", &v1, &v2);
G[v1][v2] = G[v2][v1] = ;
}
int M;
scanf("%d", &M);
for(int i = ; i < M; i++){
fill(hashTB, hashTB + , );
int K;
scanf("%d", &K);
for(int j = ; j < K; j++){
scanf("%d", &seq[j]);
hashTB[seq[j]] = ;
}
int isClque = ;
for(int j = ; j < K; j++){
for(int m = j + ; m < K; m++){
if(G[seq[j]][seq[m]] == ){
isClque = ;
break;
}
if(isClque == )
break;
}
}
int isMax = ;
for(int n = ; n <= Nv; n++){
if(hashTB[n] == ){
int tag = ;
for(int p = ; p < K; p++){
if(G[seq[p]][n] == ){
tag = ;
break;
}
}
if(tag == ){
isMax = ;
break;
}
}
}
if(isMax == && isClque == ){
printf("Yes\n");
}else if(isClque == ){
printf("Not Maximal\n");
}else{
printf("Not a Clique\n");
}
}
cin >> M;
return ;
}
总结:
1、题意:给出一个点的集合,判断这些点是否是给出的无向图的极大团。根据题意,极大团是一个点的集合:这个集合中的任意两个点之间都存在一条边,且点的个数是极大的。
2、由于给出的节点数N较少,直接暴力循环即可。对每一个待判断集合中的点,都验证它是否与集合中其它点相连接即可。极大性验证:依次检验非集合内的点,如果存在一个点v与集合内的点都连接,则不是极大团。
A1142. Maximal Clique的更多相关文章
- PAT A1142 Maximal Clique (25 分)——图
A clique is a subset of vertices of an undirected graph such that every two distinct vertices in the ...
- PAT_A1142#Maximal Clique
Source: PAT A1142 Maximal Clique (25 分) Description: A clique is a subset of vertices of an undirect ...
- PAT 甲级 1142 Maximal Clique
https://pintia.cn/problem-sets/994805342720868352/problems/994805343979159552 A clique is a subset o ...
- 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
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 (Advanced Level) Practice(更新中)
Source: PAT (Advanced Level) Practice Reference: [1]胡凡,曾磊.算法笔记[M].机械工业出版社.2016.7 Outline: 基础数据结构: 线性 ...
随机推荐
- Bootstrap 字体图标(Glyphicons)
http://www.runoob.com/bootstrap/bootstrap-glyphicons.html 什么是字体图标? 字体图标是在 Web 项目中使用的图标字体.虽然,Glyphico ...
- Day 3-5 装饰器
开放-封闭原则: 封闭:已实现的功能代码块不应该被修改. 开放:对现有功能的扩展开放. 装饰器: 定义:在符合'开放-封闭'的原则下,给程序扩展其他的功能! 例:在不更改tokyo函数的情况下.给to ...
- python学习笔记(4)-基本数据类型-数字类型及操作
大学mooc 北京理工大学 python语言程序设计课程学习笔记 一.整数类型 可正可负,没有取值范围的限制(这个与c不同,c要考虑数据类型的存储空间).如pow(x,y),计算x的y次方,pow(2 ...
- AngularJS从入门到精通
第一 AngularJS的四大特性 1. MVC 例如:使用angularjs向模板传递数据 <!doctype html> <html> <head> <m ...
- linux 查看TCP端口
如有转载,不胜荣幸.http://www.cnblogs.com/aaron-agu/ netstat –nat
- java web 开发入门 --- tomcat/servlet/jsp
在做java web 开发时,要先安装tomcat.它是一个web服务器,也叫web容器,我们把写好的jsp, html页面放到它里面,然后启动它,就可以用浏览器访问这些页面,地址栏中输入localh ...
- codevs2822
解题思路: tarjan缩点后算出度为0的点有几个,如果只有一个且这个点为爱心天使就行了: #include<iostream> #include<algorithm> #in ...
- 检测某一目录下md5相同的文件
import org.apache.commons.codec.digest.DigestUtils; import org.apache.commons.io.IOUtils; import jav ...
- BZOJ2151种树——模拟费用流+链表+堆
题目描述 A城市有一个巨大的圆形广场,为了绿化环境和净化空气,市政府决定沿圆形广场外圈种一圈树.园林部门得到指令后,初步规划出n个种树的位置,顺时针编号1到n.并且每个位置都有一个美观度Ai,如果在这 ...
- HDU5384-Hotaru's problem-Manacher
找出紧挨的三个回文串,例如abccbaabc ,形如ABA格式,其中AB为回文串.计算最长的长度. 首先用Manacher处理回文半径.然后就是找到两个点,都是偶数的回文串,并且共享了中间一段. 之后 ...