PAT A1142 Maximal Clique (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
Yes
Yes
Yes
Not Maximal
Not a Clique
#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <map>
#include <string>
#include <vector>
#include <set>
#include <cctype>
using namespace std;
const int maxn=;
int n,m,k;
set<int> adj[maxn];
int g[maxn][maxn];
int main(){
fill(g[],g[]+maxn*maxn,);
scanf("%d %d",&n,&m);
for(int i=;i<m;i++){
int c1,c2;
scanf("%d %d",&c1,&c2);
g[c1][c2]=;
g[c2][c1]=;
adj[c1].insert(c2);
adj[c2].insert(c1);
}
scanf("%d",&k);
for(int i=;i<k;i++){
int x;
scanf("%d",&x);
int que[maxn]={};
int vis[maxn]={};
for(int j=;j<x;j++){
int tmp;
scanf("%d",&tmp);
que[j]=tmp;
vis[tmp]=;
}
int flag=;
for(int j=;j<x;j++){
if(flag==){
for(int q=j+;q<x;q++){
if(g[que[j]][que[q]]==){
flag=;
printf("Not a Clique\n");
break;
}
}
}
else break;
}
if(flag==){
int flag1=,flag2=;
for(int j=;j<=n;j++){
flag2=;
if(vis[j]==) continue;
for(int q=;q<x;q++){
if(g[que[q]][j]==){
flag2=;
break;
}
}
if(flag2==){
flag1=;
printf("Not Maximal\n");
break;
}
}
if(flag1==)printf("Yes\n");
}
}
}
注意点:题目意思就是找一个团,里面每个元素之间都两两相连,如果没有另外的点可以加进去后还满足这个条件就是最大团。一开始一直在想把给定序列的元素每个遍历,找到每个元素相连的元素,再去对他们做交集,看看和给定序列一不一样。做交集这个就很麻烦了,看了大佬的思路,原来不用纠结在给定的点上,要看另外的点能不能加进来,其实就是题目里给的意思,我自己转弯了。
这种多个判断的题已经不是第一次做到了,类似的还有1150 Travelling Salesman Problem (25 分),也是和图有关,判断各种东西
PAT A1142 Maximal Clique (25 分)——图的更多相关文章
- PTA PAT排名汇总(25 分)
PAT排名汇总(25 分) 计算机程序设计能力考试(Programming Ability Test,简称PAT)旨在通过统一组织的在线考试及自动评测方法客观地评判考生的算法设计与程序设计实现能力,科 ...
- [PAT] 1142 Maximal Clique(25 分)
1142 Maximal Clique(25 分) A clique is a subset of vertices of an undirected graph such that every tw ...
- PAT 1142 Maximal Clique[难]
1142 Maximal Clique (25 分) A clique is a subset of vertices of an undirected graph such that every t ...
- A1142. Maximal Clique
A clique is a subset of vertices of an undirected graph such that every two distinct vertices in the ...
- PAT 1142 Maximal Clique
A clique is a subset of vertices of an undirected graph such that every two distinct vertices in the ...
- 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 ...
- PAT 甲级 1029 Median (25 分)(思维题,找两个队列的中位数,没想到)*
1029 Median (25 分) Given an increasing sequence S of N integers, the median is the number at the m ...
随机推荐
- 【PostMan】1、Postman 发送json格式请求
Postman 是一个用来测试Web API的Chrome 外挂软件,可由google store 免费取得并安装于Chrome里,对于有在开发Web API的开发者相当有用,省掉不少写测试页面呼叫的 ...
- Java--实现单点登录
1 什么是单点登陆 单点登录(Single Sign On),简称为 SSO,是目前比较流行的企业业务整合的解决方案之一.SSO的定义是在多个应用系统中,用户只需要登录一次就可以访问所有相互信任的应用 ...
- Opening Ceremony(贪心)
Problem E: Opening Ceremony Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 137 Solved: 30[Submit][S ...
- maven 如何依赖工程项目里面的 jar 包
前言:现在有个 jar 包在私服和公共仓库里面都没有,需要自己将 jar 包放在工程里,然后让 maven 依赖. 这里举个栗子 项目路径: pom.xml 配置 <!--自定义查询组件的jar ...
- Spring MVC异常处理 和 重定向传递数据
1.异常处理介绍 Spring在web项目中,如果在请求处理时出现异常,那输出会是Servlet响应.这时异常需要以某种方式转换为响应. Spring将异常转换为响应的方式: a.特定的Spring异 ...
- 接口自动化 基于python+Testlink+Jenkins实现的接口自动化测试框架[V2.0改进版]
基于python+Testlink+Jenkins实现的接口自动化测试框架[V2.0改进版] by:授客 QQ:1033553122 由于篇幅问题,,暂且采用网盘分享的形式: 下载地址: [授客] ...
- Java并发编程(九)并发容器
并发容器的简单介绍: ConcurrentHashMap代替同步的Map(Collections.synchronized(new HashMap())),众所周知,HashMap是根据散列值分段存储 ...
- web测试之界面测试
所谓界面测试就是指,布局是否合理.整体风格是否一致.各个控件的放置位置是否符合客户使用习惯,此外还要测试界面操作便捷性.导航简单易懂性,页面元素的可用性,界面中文字是否正确,命名是否统一,页面是否美观 ...
- 从零自学Java-10.充分利用现有对象
1.超类和子类的设计:2.建立继承层次:3.覆盖方法. 程序StringLister:使用数组列表和特殊的for循环将一系列字符串按字母顺序显示到屏幕上.这些字符串来自一个数组和命令行参数 packa ...
- matplotlib多plot可视化
代码: # -*- coding: utf-8 -*- """ Created on Thu Jul 12 16:37:47 2018 @author: zhen &qu ...