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 <cstring>
#include <cstdio>
#include <map>
#define Max 100005
using namespace std;
int nv,ne,m,k;
char re[][] = {"Not a Clique","Not Maximal","Yes"};
int mp[][],vi[],u[],v[],fir[],nex[],vis[];
int check()
{
for(int i = ;i < k;i ++)///判断集合内任意两点是否连通
{
for(int j = i + ;j < k;j ++)
{
if(!mp[vi[i]][vi[j]])return ;
}
}
///满足clique
for(int i = ;i <= nv;i ++)///判断集合外是否存在一点与集合内点都连通
{
if(!vis[i])
{
int kk = fir[i],c = ;
while(kk != -)
{
if(vis[v[kk]])c ++;
if(c >= k)return ;
kk = nex[kk];
}
}
}
///满足maximal
return ;
}
int main()
{
scanf("%d%d",&nv,&ne);
memset(fir,-,sizeof(fir));
for(int i = ;i < ne;i ++)
{
scanf("%d%d",&u[i],&v[i]);
if(u[i] == v[i])i --,ne --;
}
for(int i = ;i < ne;i ++)
{
mp[u[i]][v[i]] = mp[v[i]][u[i]] = ;
u[i + ne] = v[i];
v[i + ne] = u[i];
nex[i] = fir[u[i]];
fir[u[i]] = i;
nex[i + ne] = fir[u[i + ne]];
fir[u[i + ne]] = i + ne;
}
scanf("%d",&m);
while(m --)
{
scanf("%d",&k);
memset(vis,,sizeof(vis));
for(int i = ;i < k;i ++)
{
scanf("%d",&vi[i]);
vis[vi[i]] = ;
}
puts(re[check()]);
}
}

1142. Maximal Clique (25)的更多相关文章

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

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

  2. PAT 1142 Maximal Clique[难]

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

  3. PAT 甲级 1142 Maximal Clique

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

  4. PAT 1142 Maximal Clique

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

  5. 1142 Maximal Clique

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

  6. PAT_A1142#Maximal Clique

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

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

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

  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甲级 图 相关题_C++题解

    图 PAT (Advanced Level) Practice 用到图的存储方式,但没有用到图的算法的题目 目录 1122 Hamiltonian Cycle (25) 1126 Eulerian P ...

随机推荐

  1. es的索引库模板

    在实际的生产中,如果要插入大批量数据的时候需要使用多个索引库,如果我们还是手工指定每个索引的配置信息settings和mappings,是非常耗时的: 针对这种情况,es有index template ...

  2. HTTP入门(二):用Chrome开发者工具查看 HTTP 请求与响应

    HTTP入门(二):用Chrome开发者工具查看 HTTP 请求与响应 本文简单总结HTTP的请求与响应. 本文主要目的是对学习内容进行总结以及方便日后查阅. 详细教程和原理可以参考HTTP文档(MD ...

  3. 冲刺周四The Fourth Day

    一.Fourth Day照片 二.项目分工 三.今日份燃尽图 四.项目进展 码云团队协同环境构建完毕 利用Leangoo制作任务分工及生成燃尽图 完成AES加解密部分代码 用代码实现对文件的新建.移动 ...

  4. 数据库为什么使用B+树而不是B树

    B树和B+树的区别主要有两点: 在B树中,你可以将键和值存放在内部节点和叶子节点,但在B+树中,内部节点都是键,没有值.叶子节点同时存放键和值 B+树的叶子节点有一条链相连,而B+树的叶子节点各自独立 ...

  5. Flashtext:大规模数据清洗的利器

    Flashtext:大规模数据清洗的利器 在这篇文章中,我们将介绍一种新的关键字搜索和替换的算法:Flashtext 算法.Flashtext 算法是一个高效的字符搜索和替换算法.该算法的时间复杂度不 ...

  6. 阶段1 语言基础+高级_1-3-Java语言高级_06-File类与IO流_09 序列化流_1_序列化和反序列化的概述

  7. 阶段1 语言基础+高级_1-3-Java语言高级_06-File类与IO流_01 File类_4_File类的构造方法

    学习一个类先学习构造方法和静态方法 重写了Object类的toString方法 文件夹结尾 相对路径 第二个构造方法 两个路径组装到了一起 加上双斜线 换成d盘 第三个构造 第一个参数是一个File对 ...

  8. Java 高级-集合框架

    参考资料 参考 HashMap 类似 C++ 中的 STL 标准模板库,Java 也在 java.util 包中封装了一套常用数据结构及其算法,称为集合框架.所有的集合框架都包含如下内容: 接口:代表 ...

  9. springboot An incompatible version [1.1.32] of the APR based Apache Tomcat Native library is installed, while Tomcat requires version [1.2.14]

    1.错误 An incompatible version [1.1.32] of the APR based Apache Tomcat Native library is installed, wh ...

  10. python+selenium下拉列表option对象操作方法一

    参考官方文档:https://selenium.dev/selenium/docs/api/py/webdriver_support/selenium.webdriver.support.select ...