博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
PAT (Advanced Level) Practice 1142 Maximal Clique (25 分) 暴力
阅读量:3905 次
发布时间:2019-05-23

本文共 1774 字,大约阅读时间需要 5 分钟。

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 ))

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 105 67 86 43 64 52 38 22 75 33 464 5 4 3 63 2 8 72 2 31 13 4 3 63 3 2 1

Sample Output:

YesYesYesYesNot MaximalNot a Clique

直接暴力求解, 判断两个是否相邻。 。。

代码如下:

#include 
#include
#include
#include
#include
#include
using namespace std;const int maxn=205;int ma[maxn][maxn];int n,m,q;int a[maxn],vis[maxn];void init(){ memset (ma,0,sizeof(ma)); memset (vis,0,sizeof(vis));}int main(){ scanf("%d%d",&n,&m); init(); while (m--) { int x,y; scanf("%d%d",&x,&y); ma[x][y]=ma[y][x]=1; } scanf("%d",&q); while (q--) { memset (vis,0,sizeof(vis)); int t,flag1=0,flag2=0; scanf("%d",&t); for (int i=0;i

 

转载地址:http://bxaen.baihongyu.com/

你可能感兴趣的文章
scp port 22: Connection refused
查看>>
ubuntu12.04命令行下安装RabbitVCS
查看>>
自定义cscope-index
查看>>
(ubuntu)在andorid andk工程中使用ccache加速编译速度
查看>>
android graphics system学习资料汇总
查看>>
GDB
查看>>
Oracle RAC Failover 详解
查看>>
[转载]Oracle RAC客户端连接不稳定的解决方法
查看>>
ORA RAC ORA-12545:因目标主机或对象不存在,连接失败!
查看>>
证明两节点能正常failover的sql
查看>>
oracle10g rac 报ora-12545错误的解决方案 转载
查看>>
Linux配置Xmanager
查看>>
IP地址正则表达式
查看>>
对SOAP消息头的处理
查看>>
webservice TCP Monitor
查看>>
各系统下查看cpu物理和逻辑个数
查看>>
Oracle中sysdate的时区偏差
查看>>
【每日一算】旋转有序数组
查看>>
【每日一算】两数之和
查看>>
深入理解Mysql索引底层数据结构与算法
查看>>