Source:

PAT A1142 Maximal Clique (25 分)

Description:

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

Keys:

Attention:

  • 想的有点多,数据规模不大,暴力求解就好了

Code:

 /*
Data: 2019-08-06 20:50:04
Problem: PAT_A1142#Maximal Clique
AC: 30:25 题目大意:
判断所给子图是否是完全图(无向图)
输入:
第一行给出,顶点数Nv<=200,Ne边数
接下来Ne行,v1,v2
接下来一行,给出查询数M;
接下来M行,给出顶点数K,和K个顶点;
输出:
YES,最大完全子图;
Not Maximal,完全子图,非最大
Not a Clique,完全图 基本思路:
先判断所给子图是否是完全图,
再遍历图中其余顶点,加入该子图,判断是否为完全图
*/
#include<cstdio>
#include<algorithm>
using namespace std;
const int M=1e3,INF=1e9;
int grap[M][M],v[M],vis[M]; int main()
{
#ifdef ONLINE_JUDGE
#else
freopen("Test.txt", "r", stdin);
#endif // ONLINE_JUDGE int n,m,k,v1,v2;
scanf("%d%d", &n,&m);
fill(grap[],grap[]+M*M,INF);
for(int i=; i<m; i++)
{
scanf("%d%d", &v1,&v2);
grap[v1][v2]=;
grap[v2][v1]=;
}
scanf("%d", &m);
while(m--)
{
scanf("%d", &k);
fill(vis,vis+n+,);
for(int i=; i<k; i++)
{
scanf("%d", &v[i]);
vis[v[i]]=;
}
for(int i=; i<k-; i++)
{
v1 = v[i];
for(int j=i+; j<k; j++)
{
v2=v[j];
if(grap[v1][v2]==INF)
{
k=;
break;
}
v1=v2;
}
}
if(k==)
{
printf("Not a Clique\n");
continue;
}
for(int i=; i<=n; i++)
{
if(vis[i]==)
{
for(int j=; j<k; j++)
{
if(grap[i][v[j]]==INF)
{
vis[i]=;
break;
}
}
if(vis[i]==)
{
printf("Not Maximal\n");
k=;break;
}
}
}
if(k)
printf("Yes\n");
} return ;
}

PAT_A1142#Maximal Clique的更多相关文章

  1. A1142. Maximal Clique

    A clique is a subset of vertices of an undirected graph such that every two distinct vertices in the ...

  2. PAT A1142 Maximal Clique (25 分)——图

    A clique is a subset of vertices of an undirected graph such that every two distinct vertices in the ...

  3. PAT 甲级 1142 Maximal Clique

    https://pintia.cn/problem-sets/994805342720868352/problems/994805343979159552 A clique is a subset o ...

  4. PAT 1142 Maximal Clique[难]

    1142 Maximal Clique (25 分) A clique is a subset of vertices of an undirected graph such that every t ...

  5. [PAT] 1142 Maximal Clique(25 分)

    1142 Maximal Clique(25 分) A clique is a subset of vertices of an undirected graph such that every tw ...

  6. PAT 1142 Maximal Clique

    A clique is a subset of vertices of an undirected graph such that every two distinct vertices in the ...

  7. 1142. Maximal Clique (25)

    A clique is a subset of vertices of an undirected graph such that every two distinct vertices in the ...

  8. 1142 Maximal Clique

    题意:给出一个图,定义这样一个结点子集subset,若subset中的任意两结点不都相邻,则称之为Not a Clique:若subset中的任意两结点都相邻,则称之为Clique:若subset中的 ...

  9. Markov Random Fields

    We have seen that directed graphical models specify a factorization of the joint distribution over a ...

随机推荐

  1. 配置sublime text 前端环境

    SublimeLinter是Sublime的一个代码检测工具插件.安装前台是配置好node环境 1,在sublime text安装 SublimeLinter 按下 Ctrl+Shift+p 进入 C ...

  2. cogs 167. [USACO Mar07] 月度花费

    167. [USACO Mar07] 月度花费 ★★   输入文件:expense.in   输出文件:expense.out   简单对比时间限制:1 s   内存限制:128 MB Farmer ...

  3. mongodb之存储引擎

    前言 存储引擎是Mongodb管理数据存储主要的组件,Mongodb支持多种存储引擎,每种存储引擎适合特定的场景 WiredTiger 特性 1. version >= 3.2版本默认存储引擎2 ...

  4. solaris11-text-安装GUI(gnome)

      http://blog.chinaunix.net/xmlrpc.php?r=blog/article&uid=45057&id=3018467 1.下载所需的资源Text Ins ...

  5. 如何杀掉(kill)Oracle中的会话(Session)

    Oracle中造成一些表被死锁或者会话异常退出,如执行了更新记录操作后,既没有commit也没有rollback,网络就断开了,也会造表或记录被锁住,待到超时后才会被解开,那样都会造成应用操作被阻塞. ...

  6. ios调用dismissViewController的一个小陷阱

    我们的APP从启动到进入主页面.是通过presentViewController构造了一个ViewController序列,类似于首页 -> 登陆页 -> 启动载入页 -> 主页面 ...

  7. Android开发趣事记之周期性广告

    前些天做了一个应用,由于怕影响用户体验,所以我将广告设定了一下,就是每启动软件8次.就会弹出一次广告. 在上传到应用宝后.竟然得到了这种结果: 看到了吧.无病毒,无广告. 看来审核人员是不会把应用连续 ...

  8. 我在SharePoint行业的从业经历(二)

     本文是我的SharePoint从业经历的第二篇,第一篇请參考 我在SharePoint行业的从业经历(一) 做完那个项目之后.对SharePoint 2003有了一些认识. 可是后来几年我就没在 ...

  9. RMAN 备份与恢复 实例

    1. 检查数据库模式:    sqlplus /nolog     conn /as sysdba    archive log list (查看数据库是否处于归档模式中) 若为非归档,则修改数据库归 ...

  10. SpringMVC使用POST方法传递数据,却出现Request method 'GET' not supported?

    转自:https://segmentfault.com/q/1010000011245770 问题:没有使用get获取当前页面解决方案:   @RequestMapping(value = " ...