PAT甲级——A1141 PATRankingofInstitution【25】
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
Solution:
Yes
Yes
Yes
Not Maximal
Not a Clique
题意是,在给出的连通图中,判断查询的点是不是两两相连?如果是,那就是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】的更多相关文章
- PAT甲级——A1141 PATRankingofInstitution
After each PAT, the PAT Center will announce the ranking of institutions based on their students' pe ...
- 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 ...
- 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 ...
- pat 甲级 1010. Radix (25)
1010. Radix (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Given a pair of ...
- pat 甲级 1078. Hashing (25)
1078. Hashing (25) 时间限制 100 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue The task of t ...
- PAT 甲级 1003. Emergency (25)
1003. Emergency (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue As an emerg ...
- PAT 甲级 1078 Hashing (25 分)(简单,平方二次探测)
1078 Hashing (25 分) The task of this problem is simple: insert a sequence of distinct positive int ...
- PAT 甲级 1070 Mooncake (25 分)(结构体排序,贪心,简单)
1070 Mooncake (25 分) Mooncake is a Chinese bakery product traditionally eaten during the Mid-Autum ...
- PAT 甲级 1032 Sharing (25 分)(结构体模拟链表,结构体的赋值是深拷贝)
1032 Sharing (25 分) To store English words, one method is to use linked lists and store a word let ...
随机推荐
- swoole 安装与简单应用
方法一:PECL安装 安装依赖包 apt-get install libpcre3 libpcre3-dev 安装swoole pecl install swoole 修改PHP配置 php.ini ...
- Use sed and awk to prettify json
$ cat prettify.sed s/,/,\r\n/g s/\[/\r\n\[\r\n/g s/\]/\r\n\]\r\n/g s/{/\r\n{\r\n/g s/}/\r\n}\r\n/g $ ...
- 为什么学python
一.什么是Python Python [1](英国发音:/ˈpaɪθən/ 美国发音:/ˈpaɪθɑːn/), 是一种面向对象的解释型计算机程序设计语言,由荷兰人Guido van Rossum发明. ...
- 关于deepin下安装ssh以后root用户登陆报错的解决
最近刚刚接触到deepin,觉得,wow,除了mac,还有这么好看的非win系统,而且第测出那个Linux,宽容度很高,非常适合我这种比较喜欢折腾的人,于是下载了deepin15版本并将其当作虚拟机成 ...
- 公司redis
一: redis cluster介绍篇 1:redis cluster的现状 目前redis支持的cluster特性(已亲测): 1):节点自动发现 2):slave->master 选举,集群 ...
- mysql控制台的一些技巧,显示,输入换行,语法正则等
注释: 以/**注释内容**/ mysql> /**列出所有的数据库**/ show databases; +--------------------+ | Database | +------ ...
- elementUI table宽度自适应fit
:fit='true' 或者直接为 fit
- Codeforces The Child and Toy
The Child and Toy time limit per test1 second On Children's Day, the child got a toy from Delayyy as ...
- Nginx实现rewrite重写
目录 Rewrite基本概述 Rewrite标记Flag Rewrite规则实践 Rewrite场景示例 Rewrite规则补充 rewrite优先级实战 Rewrite基本概述 什么是rewrite ...
- 【LeetCode】Array
[11] Container With Most Water [Medium] O(n^2)的暴力解法直接TLE. 正确的解法是Two Pointers. O(n)的复杂度.保持两个指针i,j:分别指 ...