Source:

PAT A1142 Maximal Clique (25 分)

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, 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

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的更多相关文章

  1. A1142. Maximal Clique

    A clique is a subset of vertices of an undirected graph such that every two distinct vertices in the ...

  2. PAT A1142 Maximal Clique (25 分)——图

    A clique is a subset of vertices of an undirected graph such that every two distinct vertices in the ...

  3. PAT 甲级 1142 Maximal Clique

    https://pintia.cn/problem-sets/994805342720868352/problems/994805343979159552 A clique is a subset o ...

  4. PAT 1142 Maximal Clique[难]

    1142 Maximal Clique (25 分) A clique is a subset of vertices of an undirected graph such that every t ...

  5. [PAT] 1142 Maximal Clique(25 分)

    1142 Maximal Clique(25 分) A clique is a subset of vertices of an undirected graph such that every tw ...

  6. PAT 1142 Maximal Clique

    A clique is a subset of vertices of an undirected graph such that every two distinct vertices in the ...

  7. 1142. Maximal Clique (25)

    A clique is a subset of vertices of an undirected graph such that every two distinct vertices in the ...

  8. 1142 Maximal Clique

    题意:给出一个图,定义这样一个结点子集subset,若subset中的任意两结点不都相邻,则称之为Not a Clique:若subset中的任意两结点都相邻,则称之为Clique:若subset中的 ...

  9. Markov Random Fields

    We have seen that directed graphical models specify a factorization of the joint distribution over a ...

随机推荐

  1. 关于Spring的xml文档的简单实用配置

    Spring的spring.xml文档的配置 最近在写Spring的配置文件时,发现Spring文档的配置其实没必要那么繁琐记忆,网上的很多文章都写得很繁琐,如果所有的东西按照路径去查找,可以很快的帮 ...

  2. v$open_cursor中的相同record

    之前在查看v$open_cursor的时候,发现很多相同的record. 让我很疑惑, sid saddr sql_id 都相同,我就想 这不是一个cursor吗? 那为什么在open_cursor中 ...

  3. [Cypress] Test Variations of a Feature in Cypress with a data-driven Test

    Many applications have features that can be used with slight variations. Instead of maintaining mult ...

  4. iOS分组通讯录效果+側滑菜单(MMDrawerController)

    前言的废话-能够忽略 自从学会了使用Cocoapod,就欲罢不能了!由于太简单太赞了,不用再把源代码粘到project里了! 參见戴维营博客中的解说:Cocoapod 安装以及使用 先上一下效果图,请 ...

  5. Java时间转换

    package com.fh.util; import java.sql.Timestamp; import java.text.DateFormat; import java.text.ParseE ...

  6. OpenCV:Visual Studio 2013 Ultimate中OpenCV 2.4.8 配置

    配置环境: 操作系统:Win8.1  64位 IDE平台:Visual Studio 2013 Ultimate 一.准备OpenCV 2.4.8 1.下载:从官网下载 OpenCV2.4.8:   ...

  7. jQuery总结04

    1 JavaScript 中的 AJAX 的四个实现步骤分别是? 2 如何处理 XMLHttpRequest 对象的兼容问题? 3 jQuery 中的 AJAX 4 jQuery 选择器包括哪些? 5 ...

  8. CentOs7 修改rpm安装背景图

    http://bbs.chinaunix.net/thread-4166176-1-1.html

  9. yii widget使用的3个用法

    yii视图中使用的widget方式总结:常用的有3种方式:一.显示详细信息: $this->widget('zii.widgets.CDetailView', array( 'data' =&g ...

  10. WebService开发-CXF

    Web Service 开发方式 Apache CXF 一.关于Apache CXF 在网址http://cxf.apache.org/可以查看到关于Apache CXF的下载及文档介绍,这里不再多做 ...