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的更多相关文章

  1. PAT A1142 Maximal Clique (25 分)——图

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

  2. PAT_A1142#Maximal Clique

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

  3. PAT 甲级 1142 Maximal Clique

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

  4. PAT 1142 Maximal Clique[难]

    1142 Maximal Clique (25 分) A clique is a subset of vertices of an undirected graph such that every t ...

  5. [PAT] 1142 Maximal Clique(25 分)

    1142 Maximal Clique(25 分) A clique is a subset of vertices of an undirected graph such that every tw ...

  6. PAT 1142 Maximal Clique

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

  7. 1142. Maximal Clique (25)

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

  8. 1142 Maximal Clique

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

  9. PAT (Advanced Level) Practice(更新中)

    Source: PAT (Advanced Level) Practice Reference: [1]胡凡,曾磊.算法笔记[M].机械工业出版社.2016.7 Outline: 基础数据结构: 线性 ...

随机推荐

  1. 运行pip报错:Fatal error in launcher: Unable to create process using '"'

    参考: https://blog.csdn.net/cjeric/article/details/73518782

  2. Redis事物

    redis事物定义: >Redis事务是一个单独的隔离操作:事务中的所有命令都会序列化.按顺序地执行.事务在执行的过程中,不会被其他客户端发送来的命令请求所打断. >Redis事务的主要作 ...

  3. Helm

    helm类似yum helm下载的是配置清单文件 核心术语: Chart:一个helm程序包: Repository:Charts仓库,https/http服务器: Release:特定的Chart部 ...

  4. 对C#调用C++的dll的一点思考

    最近在对接C++程序的时候碰到了一些问题,然后花了一段时间才解决,今天就这些小问题来做一个总结,很多时候由于对另外一种开发语言的不熟悉,会在使用的过程中遇到很多的问题,这些问题看似简单但是背后却有很多 ...

  5. Prism框架中加载类库中时其中第三方类dll提示无法加载程序集

    Prism框架是采用一种依赖注入的方式动态加载程序集,能够在程序需要加载的时候将程序集注入到里面去,实现程序的热插拔效果,而且采用这种框架能够让我们进行一个大项目的独立开发,在最近的一个项目中在独立开 ...

  6. 相识mongodb

    1.下载完安装包,并解压下载地址:https://www.mongodb.org/dl/linux/x86_64或者可以直接wget http://fastdl.mongodb.org/linux/m ...

  7. 个人用的感觉比较舒服的 idea 插件,不定时更新

    1.mybatis plugin 用的最舒服的 idea 上的 plugin 之一,快速跳转 dao 的映射的 xml 文件,生成配置文件.语法提示等 不过这个收费,,具体步骤百度吧 2.Rainbo ...

  8. postfix 邮箱设置及常见错误

    postfix 邮箱设置及常见错误 1.如果装了sendmail的话,先卸载了. yum remove sendmail 2.安装 Postfix yum install postfix 3.更改默认 ...

  9. 将数组Arrays转成集合List

    String[] split = pids.split("-"); //将数组split转成集合 List<String> asList = Arrays.asList ...

  10. JarvisOJ Basic 熟悉的声音

    两种元素,还有声音,想到了莫尔斯电码,解码得到 jbluwewnz 提交,发现不对,觉得应该是有实际意义的东西,实在想不到还能怎么解,就去看了题解. 发现这个还可以再套一个凯撒密码,就拿python写 ...