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基础命令及使用帮助
一.内部命令 内置命令(builtin):由shell程序自带的命令 help:查看内部命令 enable -n command 禁用某内部命令 enable -n 查看全部被禁用的命令 enable ...
- layer.open()中属性content在IE 8中提示“网页无法显示”
将图中的${ctx}值为 将${ctx}更改为BASEURI 如图: 若是在IE8上中弹出框中还是显示网页无法显示.可以改为 content:‘http://127.0.0.1:8081/projec ...
- 大数据笔记(四)——操作HDFS
一.Web Console:端口50070 二.HDFS的命令行操作 (一)普通操作命令 HDFS 操作命令帮助信息: hdfs dfs + Enter键 常见命令 1. -mkdir 在HDFS上 ...
- win7 编译postgresql9.6.8
一.环境 windows7 postgresql9.6.8 vs2010 perl5.24.3 二.编译安装 1.安装perl,安装到C:\Perl64路径下,安装完成后设置环境变量PATH和Perl ...
- ORACLE Physical Standby DG 之switch over
DG架构图如下: 计划,切换之后的架构图: DG切换: 主备切换:这里所有的数据库数据文件.日志文件的路径是一致的 [旧主库]主库primarydb切换为备库standby3主库检查switchove ...
- 洛谷P4317 花(fa)神的数论题(数位dp解法)
日常废话: 完了高一开学第二天作业就写不完了药丸(其实第一天就写不完了) 传传传传传送 显然爆搜肯定过不了这道题但是有60分 我们注意到在[1,n]中,有着相同的1的个数的数有很多.若有x个数有i个1 ...
- qbzt day2 下午
内容提要 高精 矩阵 筛法 先是高精除法 注意细节 高精度开方:神奇的竖式 以小数点为分界线,每两个位砍一刀 87654.321-->08|76|54|.32|1 大概就是先对第一位开方,然后相 ...
- #Week 11 - 343.Integer Break
Week 11 - 343.Integer Break Given a positive integer n, break it into the sum of at least two positi ...
- Week 9 - 638.Shopping Offers - Medium
638.Shopping Offers - Medium In LeetCode Store, there are some kinds of items to sell. Each item has ...
- IPv6 首部格式
<图解TCP/IP> 4.8 IPv6的首部格式 IPv6为了减轻路由器的负担,省略了首部校验和字段.因此路由器不再需要计算校验和,从而提高了包的转发效率. 此外,分片处理所用的识别码成为 ...