PAT_A1142#Maximal Clique
Source:
Description:
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, printNot Maximal
; or if it is not a clique at all, printNot 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
Keys:
Attention:
- 想的有点多,数据规模不大,暴力求解就好了
Code:
/*
Data: 2019-08-06 20:50:04
Problem: PAT_A1142#Maximal Clique
AC: 30:25 题目大意:
判断所给子图是否是完全图(无向图)
输入:
第一行给出,顶点数Nv<=200,Ne边数
接下来Ne行,v1,v2
接下来一行,给出查询数M;
接下来M行,给出顶点数K,和K个顶点;
输出:
YES,最大完全子图;
Not Maximal,完全子图,非最大
Not a Clique,完全图 基本思路:
先判断所给子图是否是完全图,
再遍历图中其余顶点,加入该子图,判断是否为完全图
*/
#include<cstdio>
#include<algorithm>
using namespace std;
const int M=1e3,INF=1e9;
int grap[M][M],v[M],vis[M]; int main()
{
#ifdef ONLINE_JUDGE
#else
freopen("Test.txt", "r", stdin);
#endif // ONLINE_JUDGE int n,m,k,v1,v2;
scanf("%d%d", &n,&m);
fill(grap[],grap[]+M*M,INF);
for(int i=; i<m; i++)
{
scanf("%d%d", &v1,&v2);
grap[v1][v2]=;
grap[v2][v1]=;
}
scanf("%d", &m);
while(m--)
{
scanf("%d", &k);
fill(vis,vis+n+,);
for(int i=; i<k; i++)
{
scanf("%d", &v[i]);
vis[v[i]]=;
}
for(int i=; i<k-; i++)
{
v1 = v[i];
for(int j=i+; j<k; j++)
{
v2=v[j];
if(grap[v1][v2]==INF)
{
k=;
break;
}
v1=v2;
}
}
if(k==)
{
printf("Not a Clique\n");
continue;
}
for(int i=; i<=n; i++)
{
if(vis[i]==)
{
for(int j=; j<k; j++)
{
if(grap[i][v[j]]==INF)
{
vis[i]=;
break;
}
}
if(vis[i]==)
{
printf("Not Maximal\n");
k=;break;
}
}
}
if(k)
printf("Yes\n");
} return ;
}
PAT_A1142#Maximal Clique的更多相关文章
- A1142. Maximal Clique
A clique is a subset of vertices of an undirected graph such that every two distinct vertices in the ...
- PAT A1142 Maximal Clique (25 分)——图
A clique is a subset of vertices of an undirected graph such that every two distinct vertices in the ...
- PAT 甲级 1142 Maximal Clique
https://pintia.cn/problem-sets/994805342720868352/problems/994805343979159552 A clique is a subset o ...
- 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(25 分)
1142 Maximal Clique(25 分) A clique is a subset of vertices of an undirected graph such that every tw ...
- 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 (25)
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中的 ...
- Markov Random Fields
We have seen that directed graphical models specify a factorization of the joint distribution over a ...
随机推荐
- F1: A Distributed SQL Database That Scales GOOGLE F1 论文
http://research.google.com/pubs/pub41344.html http://research.google.com/pubs/pub36726.html
- MYSQL 字符集 MYSQL 源码
http://blog.csdn.net/maray/article/details/46504621
- [转]十五天精通WCF——第十天 学会用SvcConfigEditor来简化配置
我们在玩wcf项目的时候,都是自己手工编写system.serviceModel下面的配置,虽然在webconfig中做wcf的服务配置的时候,vs提供大多 数的代码提示,但对于不太熟悉服务配置的小鸟 ...
- dataguard switchover to physical stnadby
首先做一系列的check check 当前primary 的 standby redo log是否存在 SQL> select * from v$logfile; GROUP# STATUS T ...
- Androd自己定义控件(三)飞翔的小火箭
在前面的自己定义控件概述中已经跟大家分享了Android开发其中自己定义控件的种类. 今天跟大家分享一个非主流的组合控件. 我们在开发其中,难免须要在不同的场合中反复使用一些控件的组合.而Java的最 ...
- HDU 4522
DIJK,最短路,建两个图就好了. #include <cstdlib> #include <cstdio> #include <cstring> #include ...
- 【原创】TCP超时重传机制探索
TCP超时重传机制探索 作者:tll (360电商技术) 1)通信模型 TCP(Transmission Control Protocol)是一种可靠传输协议.在传输过程中当发送方(sender)向接 ...
- Wscript对象具体解释
15.6 Windows脚本宿主的内建对象 每一个编程环境都提供了自己的对象模型,开发者 能够使用这些对象模型实现各种解决方式,WSH也不例外.WSH包括了一组核心对象,分别包括了属性和方法,能够用 ...
- JAVA正則表達式小总结
近期项目中正在做后台校验,而后台校验也基本都是使用正則表達式校验.本文做一些粗略的总结. 1.字符串长度:.{1,10},注意有一个点在{}前,表示匹配全部.'{}'之前一定是一个捕获组,因此假设有其 ...
- Java 错误:找不到或无法加载主类(源文件中含有包名 package)
1. 问题定位 编译(javac)和执行(java)java 程序时,出现这种类型的错误:找不到或无法加载主类: 首先排除是否是环境变量配置不当造成的问题,只要保证,命令行界面能够识别 javac/j ...