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. C#进阶系列——WebApi 路由机制剖析:你准备好了吗? 转载https://www.cnblogs.com/landeanfen/p/5501490.html

    阅读目录 一.MVC和WebApi路由机制比较 1.MVC里面的路由 2.WebApi里面的路由 二.WebApi路由基础 1.默认路由 2.自定义路由 3.路由原理 三.WebApi路由过程 1.根 ...

  2. 嵌入式C语言3.5 关键字---运算符

    1. 算数运算符 + -                    A +/- B 要求A,B数据类型一致 * 乘法   / 除法    %取模 乘法CPU可能需要多个周期,甚至需要利用软件的模拟方法来实 ...

  3. 1.如何在JMeter中使用JUnit

    您是否需要在测试过程中使用JUnit? 要回答这个问题,我们先来看看单元测试. 单元测试是软件测试生命周期中测试的最低分辨率. 运行单元测试时,需要在应用程序中使用最小的可测试功能,将其与其他代码隔离 ...

  4. js日历算法

    页面 <div class="un1"> <h2>服务档期</h2> <div class="date-panel" ...

  5. viewport的深入调研

    1.viewport概念:viewport就是设备的屏幕上能用来显示我们的网页的那一块区域. viewport的默认值980px或1024px等,以下是浏览器的默认viewport宽度 2.css中的 ...

  6. Windows及MAC 安装Python3.7.4

    Windows没有Python环境,Mac自带Python 2,所以开发者需要下载Python 3进行开发相关工作,此文章介绍如何安装Python,Mac安装前可以在终端数输入python查看自带版本 ...

  7. python-opencv实现简单的车牌定位

    车牌定位的原理:https://blog.csdn.net/relocy/article/details/78705662 训练好的分类器:https://github.com/zeusees/Hyp ...

  8. 配置进程外Session 同时解决一个奇怪的BUG 因为SQLserver 服务器名不是默认的.或者localhost而引发的一系列问题

    用公司的电脑学习如鹏网的视频,开发一个项目,用到了进程外session,因为公司电脑SQLServer 是2008 服务器名称是.  然后参考这篇文章进行设置进程外session 很顺利 完成了设置. ...

  9. LeetCode Array Easy 283. Move Zeroes

    Description Given an array nums, write a function to move all 0's to the end of it while maintaining ...

  10. 拓展练习--find查找、打包压缩、服务器、磁盘挂载

    目录 find查找.打包压缩 服务器部分 磁盘挂载及单用户模式 find查找.打包压缩 1.超级用户(管理员用户)提示符是_#,普通用户提示符是$_. 2.如何快速返回上一次所在的目录? cd - 3 ...