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 ...
随机推荐
- linux 文件相关常用命令
文件或者目录操控命令 1,cd切换目录. 其中- 代表前一个目录 2,mkdir 新建目录. 加上-p参数可以递归创建多级目录 mkdir -p test1/test2/test3 3,rmdir删除 ...
- MySQL Schedule Event
建立事件历史日志表-- 用于查看事件执行时间等信息create table t_event_history ( dbname varchar(128) not null default ' ...
- 20175221曾祥杰 实验三《敏捷开发与XP实践》
实验三<敏捷开发与XP实践> 实验报告封面 课程:Java程序设计 班级:1752班 姓名:曾祥杰 学号:20175221 指导教师:娄嘉鹏 实验日期:2019年4月30日 实验时间:13 ...
- Week13 - 376. Wiggle Subsequence
Week13 - 376. Wiggle Subsequence A sequence of numbers is called a wiggle sequence if the difference ...
- UIAutomation元素识别软件
通过Python调用UIAutomation库来开发代码时,都会遇到需要识别元素的问题.笔者在这里推荐两款好用的软件:UISpy和Inspect. UISpy识别元素后,我们需要的属性有:ClassN ...
- day18 时间:time:,日历:calendar,可以运算的时间:datatime,系统:sys, 操作系统:os,系统路径操作:os.path,跨文件夹移动文件,递归删除的思路,递归遍历打印目标路径中所有的txt文件,项目开发周期
复习 ''' 1.跨文件夹导包 - 不用考虑包的情况下直接导入文件夹(包)下的具体模块 2.__name__: py自执行 '__main__' | py被导入执行 '模块名' 3.包:一系列模块的集 ...
- Monte Carlo Control
Problem of State-Value Function Similar as Policy Iteration in Model-Based Learning, Generalized Pol ...
- VC调试方法大全
VC调试方法大全 一.调试基础 调试快捷键 F5: 开始调试 Shift+F5: 停止调试 F10: 调试到下一句,这里是单步跟踪 F11: 调试到下一句,跟进函数内部 Shift+F11: ...
- 如何让cmd启动始终以管理员身份运行(方法已失效)
神来之图--实测以下方法已经不能使用,辗转看了好多文章,内容基本如下图,不知道谁转的谁的,总之已经是不能用的文章了.在此记录一下.至于解决办法目前没有找到,之前随笔中有提到新建一个cmd命令提示符的快 ...
- CDH平台搭建解决离线安装依赖包的方法
背景介绍: 1CDH开发平台在搭建的过程中,会遇到各种各样的问题,其中的各种依赖就是一个很让人头痛的问题.如果安装脚本文件出现了这种问题,那么就可以把以下的这种方法加入shell中,但是不要用yum来 ...