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 ...
随机推荐
- 正则表达式小结,数据预处理中常用的shell命令
数据预处理中,这部分命令非常有用. 不需要编写代码,直接通过shell脚本通常就能修改文件格式.有时候sed和awk联合几乎能实现所有功能. 管道命令 | 重定向命令>,2>,>&g ...
- 深入理解BFC和IFC
1. 为什么会有BFC和IFC 首先要先了解两个概念:Box和formatting context: Box:CSS渲染的时候是以Box作为渲染的基本单位.Box的类型由元素的类型和display属性 ...
- (转)CBC模式和ECB模式解读
一 什么是CBC模式 CBC模式的全称是Cipher Block Chaining模式(密文分组链接模式),之所以叫这个名字,是因为密文分组像链条一样相互连接在一起. 在CBC模式中,首先将明文分组与 ...
- ASP 解析json
第一个方法是使用 JScript : <script language="jscript" runat="server"> Array.protot ...
- 查看磁盘和文件的使用情况df和du
df, du: disk filesystem, disk usage. df : 查看一级目录的使用情况, df -h du: 则是可以查看目录或者某个文件的占用磁盘空间的情况, du -h: 使用 ...
- 关于问题的四个单词区别: question problem matter issue
[[ 网上讨论的 problem, question, issue, matter这些名词均含"问题"之意.problem: 指客观上存在的.难以处理或难以理解的问题.questi ...
- base64加密小案例
python终端下: import base64 >>> dict='{"name":"tom"}' >>> dict.en ...
- Vue知识整理4:v-html标签
可以在数据绑定中使用html标签,这样在变量里可以使用html标签输出结果,如下所示:
- nginx坑记录
问题1: 配置解析过程使用ngx_cycle->pool申请内存保存配置,结果造成野指针. 背景:需求开发过程,有一些结构需要在配置解析阶段保存,然后可以动态修改.看原来的代码配置解析都是使用c ...
- 博客图片上传picgo工具安装配置github图传使用
摘要 对于每一个写博客的人来说,图片是至关重要.这一路经历了多次图片的烦恼,之前选择了微博个人文章那里粘贴图片的方式上传,感觉也挺方便的.但是由于新浪的图片显示问题,如果header中不设置 标签就不 ...