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. HTML5经典案例学习-----新元素添加文档结构

    直接上代码了,大家如果发现问题了,记得提醒我哦,谢谢啦,嘻嘻 <!DOCTYPE html> <!-- 不区分大小写 --> <html lang="en&qu ...

  2. Struts2——通配符,Action Method_DMI

    Action wildcard 通配符(配置量降到最低) 使用通配符,就是为了配置简便,但是一定遵守“约定优于配置”原则,约定就是做项目之前最好事先与项目组的人或是自己规定好命名规则. 多个*  {1 ...

  3. hive条件函数

    case相当于if,when相当于=:then是条件满足的结论.否则实行else后语句,一end结束

  4. 在阿里云上部署 Postfix

    Postfix 可以很方便的在一台机器上部署 smtp 服务,在 centos 上来说的话可以使用: sudo yum install postfix sudo systemctl enable po ...

  5. Shell 编程和Python编程的那些不同之处(一)

    循环 shell中for循环的表现形式: 1.数字段形式 for i in {1..10};do  echo $i;done 还支持按规定的步数进行跳跃的方式实现列表for循环,例如计算1-100内所 ...

  6. Java使用RabbitMQ之公平分发

    发送消息: package org.study.workfair; import com.rabbitmq.client.Channel; import com.rabbitmq.client.Con ...

  7. python排序 sorted()与list.sort() (转)

    该文章为转载:原文地址为:https://www.cnblogs.com/zuizui1204/p/6422939.html 只要是可迭代对象都可以用sorted . sorted(itrearble ...

  8. tensorflow点滴笔记

    1.模型保存 模型保存需要使用函数 tf.train.Saver(), a)创建saver时,可以指定需要存储的tensor,如果没有指定,则全部保存. b) 创建saver时,可以指定保存的模型个数 ...

  9. 解决post、get端中文乱码问题

    在web.xml中配置: <filter> <filter-name>CharacterEncodingFilter</filter-name> <filte ...

  10. Vue入门基础

    前面的话 Vue中文文档写得很好,界面清爽,内容翔实.但文档毕竟不是教程,文档一上来出现了大量的新概念,对于新手而言,并不友好.个人还是比较喜欢类似于<JS高级程序设计>的风格,从浅入深, ...