1142. Maximal Clique (25)
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)的更多相关文章
- [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[难]
1142 Maximal Clique (25 分) A clique is a subset of vertices of an undirected graph such that every t ...
- PAT 甲级 1142 Maximal Clique
https://pintia.cn/problem-sets/994805342720868352/problems/994805343979159552 A clique is a subset o ...
- 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
题意:给出一个图,定义这样一个结点子集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 ...
- PAT A1142 Maximal Clique (25 分)——图
A clique is a subset of vertices of an undirected graph such that every two distinct vertices in the ...
- A1142. Maximal Clique
A clique is a subset of vertices of an undirected graph such that every two distinct vertices in the ...
- PAT甲级 图 相关题_C++题解
图 PAT (Advanced Level) Practice 用到图的存储方式,但没有用到图的算法的题目 目录 1122 Hamiltonian Cycle (25) 1126 Eulerian P ...
随机推荐
- Java数据结构之排序---冒泡排序
冒泡排序的基本思想: 通过对待排序序列从前到后(从下标小的元素开始),依次比较相邻位置的元素的值,若发现与给定的次序冲突,则交换位置(假设数值大的数放在序列的后面),使数值较大的元素逐渐从前移动到后部 ...
- 电脑配置Java环境变量之后,在cmd中仍然无法识别
在电脑上配置了Java的环境变量,但是在cmd框中仍然无法识别: 解决方法:cmd.exe右键---以管理员身份运行,即可识别
- 2018-2019-2 20175214 实验三《敏捷开发与XP实践》实验报告
一.实验内容 1.编码标准:在IDEA中使用工具(Code->Reformate Code)把下面代码重新格式化,再研究一下Code菜单,找出一项让自己感觉最好用的功能.提交截图,加上自己学号水 ...
- CS2001 VS编译错误
Severity Code Description Project File Line Suppression State Error CS2001 Source file 'C:\Workspace ...
- 九、MySQL报错( (1292, u"Truncated incorrect DOUBLE value: '424a000000066'") result = self._query(query))
1.数据库sql语句:SELECT seat_id FROM netsale_order_seat os join netsale_order nor on os.order_code=nor.ord ...
- SynchronousQueue 源码分析
SynchronousQueue SynchronousQueue 能解决什么问题?什么时候使用 SynchronousQueue? 1)SynchronousQueue 没有任何内部容量. 2)Sy ...
- 阶段1 语言基础+高级_1-3-Java语言高级_05-异常与多线程_第3节 线程同步机制_1_线程安全问题的概述
- Spring学习01——HelloSpring
这是一个spring入门demo: package com.su.test; public class HelloWorld { public void say(){ System.out.print ...
- SpringBoot整合SpringMVC完成文件上传
1.编写Controller /** * SPringBoot文件上传 */ //@Controller @RestController //表示该类下的方法的返回值会自动做json格式的转换 pub ...
- package__init__用途
baidu包,假设在baidu包下有N个模块,分别是baidu1.py.baidu2.py,baidu3.py, baiduHq.py(baidu1.py,baidu2.py,baidu3.py模块代 ...