A clique is a subset of vertices of an undirected graph such that every two distinct vertices in the clique are adjacent. A maximal cliqueis 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<algorithm>
#include<cstdio>
using namespace std;
int G[][] = {};
int Nv, Ne;
int seq[], hashTB[];
int main(){
scanf("%d%d", &Nv, &Ne);
for(int i = ; i < Ne; i++){
int v1, v2;
scanf("%d%d", &v1, &v2);
G[v1][v2] = G[v2][v1] = ;
}
int M;
scanf("%d", &M);
for(int i = ; i < M; i++){
fill(hashTB, hashTB + , );
int K;
scanf("%d", &K);
for(int j = ; j < K; j++){
scanf("%d", &seq[j]);
hashTB[seq[j]] = ;
}
int isClque = ;
for(int j = ; j < K; j++){
for(int m = j + ; m < K; m++){
if(G[seq[j]][seq[m]] == ){
isClque = ;
break;
}
if(isClque == )
break;
}
}
int isMax = ;
for(int n = ; n <= Nv; n++){
if(hashTB[n] == ){
int tag = ;
for(int p = ; p < K; p++){
if(G[seq[p]][n] == ){
tag = ;
break;
}
}
if(tag == ){
isMax = ;
break;
}
}
}
if(isMax == && isClque == ){
printf("Yes\n");
}else if(isClque == ){
printf("Not Maximal\n");
}else{
printf("Not a Clique\n");
}
}
cin >> M;
return ;
}

总结:

1、题意:给出一个点的集合,判断这些点是否是给出的无向图的极大团。根据题意,极大团是一个点的集合:这个集合中的任意两个点之间都存在一条边,且点的个数是极大的。

2、由于给出的节点数N较少,直接暴力循环即可。对每一个待判断集合中的点,都验证它是否与集合中其它点相连接即可。极大性验证:依次检验非集合内的点,如果存在一个点v与集合内的点都连接,则不是极大团。

A1142. Maximal Clique的更多相关文章

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

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

  2. PAT_A1142#Maximal Clique

    Source: PAT A1142 Maximal Clique (25 分) Description: A clique is a subset of vertices of an undirect ...

  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. PAT (Advanced Level) Practice(更新中)

    Source: PAT (Advanced Level) Practice Reference: [1]胡凡,曾磊.算法笔记[M].机械工业出版社.2016.7 Outline: 基础数据结构: 线性 ...

随机推荐

  1. .Net批量插入数据

    1. 一般我们普通数据插入是这样的: 现在我们写一个控制台程序用常规办法添加10000条数据. //以下是批量插入数据的办法 //连接字符串 string str = "Server=.;D ...

  2. 安装sqlprompt

    特别说明:注册机会报毒,安装前请先关闭杀毒软件!下载好附件之后解压,打开SQLPrompt_7.2.0.241.exe按照提示安装完成.安装完成后断网!打开数据库,会在菜单栏中看到SQL Prompt ...

  3. Flutter路由管理

    第一点:push使用 1.pushNamed——Navigator.of(context).pushNamed('routeName'); 此种方法只是简单的将我们需要进入的页面push到栈顶,以此来 ...

  4. Android——MaterialDesign之四 FloatingActionButton、Snackbar、CoordinaterLayout

    FloatingActionButton 悬浮按钮,默认colorAccent来作为按钮的颜色 <android.support.design.widget.FloatingActionButt ...

  5. 设计模式笔记:开闭原则(OCP,The Open-Closed Principle)

    1. 开闭原则概述 开闭原则(OCP,The Open-Closed Principle)两个主要特征: (1)对扩展开放(open for extension):模块的行为的可以扩展的,当应用的需求 ...

  6. PyCharm的使用

    1.pycharm的下载和安装 首先,去jetbrains官网https://www.jetbrains.com/pycharm/download/#section=windows 中下载最新版的pr ...

  7. Linux命令替换字符串

    :%s/str1/str2/ 用str2替换str1

  8. Zero to Build: Create new Xamarin apps in minutes with AppMap

    Creating a new Xamarin.Forms app can be an intimidating task, especially if you add in content pages ...

  9. codeforces285B

    Find Marble CodeForces - 285B Petya and Vasya are playing a game. Petya's got n non-transparent glas ...

  10. hdu-1421(dp)

    解题思路:dp[i][j]表示前i个物品中取k对所要的最小花费: 首先得对物品进行处理,因为需要当前物品减前一个物品的平方和最小: 所以先排序,因为排序的相邻两个的差的平方一定最小: 然后转移方程:d ...