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
Solution:
  题意是,在给出的连通图中,判断查询的点是不是两两相连?如果是,那就是Clique,然后在判断这些查询点是是不是最大的集,即没有其他的点与查询的点是两两相连的
  若存在,则不是最大集
  
 #include <iostream>
#include <vector>
using namespace std;
int main()
{
int n, m, k;
cin >> n >> m;
vector<vector<int>>v(n + , vector<int>(n + , ));
while (m--)
{
int a, b;
cin >> a >> b;
v[a][b] = v[b][a] = ;
}
cin >> k;
while (k--)
{
cin >> m;
vector<int>temp(m);
vector<bool>otherNum(n + , true);
for (int i = ; i < m; ++i)
{
cin >> temp[i];
otherNum[temp[i]] = false;
}
bool flag = true, isMax = true;
for (int i = ; i < m && flag; ++i)//判断查询的点是不是两两相连
for (int j = i + ; j < m; ++j)
if (v[temp[i]][temp[j]] == )
flag = false;
if (flag == false)
cout << "Not a Clique" << endl;
else
{
for (int i = ; i <= n && isMax; ++i)//判断查询之外的点与查询中的点是不是两两相连
{
if (otherNum[i] == false)continue;//在查询中的点不用判断
int nums = ;
for (int j = ; j < m; ++j)
if (v[i][temp[j]] == )
++nums;
if (nums == m)
isMax = false;
}
if (isMax)
cout << "Yes" << endl;
else
cout << "Not Maximal" << endl;
}
}
return ;
}
												

PAT甲级——A1141 PATRankingofInstitution【25】的更多相关文章

  1. PAT甲级——A1141 PATRankingofInstitution

    After each PAT, the PAT Center will announce the ranking of institutions based on their students' pe ...

  2. PAT 甲级 1010 Radix (25)(25 分)进制匹配(听说要用二分,历经坎坷,终于AC)

    1010 Radix (25)(25 分) Given a pair of positive integers, for example, 6 and 110, can this equation 6 ...

  3. PAT 甲级1003 Emergency (25)(25 分)(Dikjstra,也可以自己到自己!)

    As an emergency rescue team leader of a city, you are given a special map of your country. The map s ...

  4. pat 甲级 1010. Radix (25)

    1010. Radix (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Given a pair of ...

  5. pat 甲级 1078. Hashing (25)

    1078. Hashing (25) 时间限制 100 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue The task of t ...

  6. PAT 甲级 1003. Emergency (25)

    1003. Emergency (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue As an emerg ...

  7. PAT 甲级 1078 Hashing (25 分)(简单,平方二次探测)

    1078 Hashing (25 分)   The task of this problem is simple: insert a sequence of distinct positive int ...

  8. PAT 甲级 1070 Mooncake (25 分)(结构体排序,贪心,简单)

    1070 Mooncake (25 分)   Mooncake is a Chinese bakery product traditionally eaten during the Mid-Autum ...

  9. PAT 甲级 1032 Sharing (25 分)(结构体模拟链表,结构体的赋值是深拷贝)

    1032 Sharing (25 分)   To store English words, one method is to use linked lists and store a word let ...

随机推荐

  1. Linux下实现MySQL数据库每天定时自动备份

    使用MySQL自带的备份工具+ crontab 的方式来实现备份 1.查看磁盘挂载信息(选一个容量合适的) #df -h 2.创建备份目录 为了方便,在/home保存备份文件: cd /home/ga ...

  2. 【awk】 判断是不是纯ascii串

    筛选出纯ascii串: awk '{ l = length($0); for (i = l; i > 0; i--) { if (substr($0,i,1) > "\177&q ...

  3. Python中的内置函数和匿名函数

    1. 内置函数 print用法 def print(self, *args, sep=' ', end='\n', file=None): # known special case of print ...

  4. SQL分支语句与循环语句

    分支语句 if then elsif then else end if 举例: set serveroutput on declare num number; begin num:; then dbm ...

  5. FZU 2059 MM

    Description There is a array contain N(1<N<=100000) numbers. Now give you M(1<M<10000) q ...

  6. JavaScript学习笔记(基础部分)

    一.JavaScript简介: 概念:JavaScript是一种解释性的.跨平台的.基于对象的脚本语言,一般用于客户端来给HTML页面增加动态的功能. 组成: 1.ECMAScript,描述了该语言的 ...

  7. Python中dict的特点

    dict的第一个特点是查找速度快,无论dict有10个元素还是10万个元素,查找速度都一样.而list的查找速度随着元素增加而逐渐下降. 不过dict的查找速度快不是没有代价的,dict的缺点是占用内 ...

  8. windows系统下MySQL中遇到1045问题

    报错内容为"1045    Access denied for user 'root'@'localhost' (using password:YES)",对应的原因是密码错误,如 ...

  9. Hibernate的优点与缺点

    Hibernate优点: 1.对象化.人员以面相对象的思想来操作数据库.Hibernate支持许多面向对象的特性,如组合,继承,多态等. 2.更好的移植性.对于不同的数据库,开发者只需要使用相同的数据 ...

  10. Java中"String.equals()“和"=="的区别

    Do NOT use the `==`` operator to test whether two strings are equal! It only determines whether or n ...