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. Unity3D中的Coroutine具体解释

    本文太乱,推荐frankjfwang的:全面解析Coroutine技术 Unity中的coroutine是通过yield expression;来实现的.官方脚本中到处会看到这种代码. 疑问: yie ...

  2. StringIndexOutOfBoundsException

    <span style="font-family:Microsoft YaHei;font-size:14px;">public class StringIndexBo ...

  3. QueryString 地址栏参数

    MXS&Vincene  ─╄OvЁ  &0000002 ─╄OvЁ  MXS&Vincene MXS&Vincene  ─╄OvЁ:今天很残酷,明天更残酷,后天很美好 ...

  4. 2014.8.12-AKKA和Actor model 分布式开发环境学习小结

    学习使用AKKA 断断续续有一年了. 眼下还是习惯用java来写akka以下的程序.对于原生的scala还是没有时间和兴趣去学习它. 毕竟学习一门语言须要兴趣和时间的. AKKA学习资源还是不算丰富. ...

  5. luogu1631 序列合并

    题目大意 有两个序列A,B,在A和B中各取一个数相加能得到$n^2$个和.求出这些和前n小的数字. 题解 首先这道题不可以用自己想的什么A序列B序列各两个指针的自己发明的模拟算法,用这样的算法只能是绝 ...

  6. WebView 用法总结

    1.AndroidManifest.xml中必须使用许可"android.permission.INTERNET",否则会出 Web page not available 错误. ...

  7. hdu 1542(线段树+扫描线 求矩形相交面积)

    Atlantis Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Su ...

  8. 【POJ 1456】 Supermarket

    [题目链接] http://poj.org/problem?id=1456 [算法] 贪心 + 堆 [代码] #include <algorithm> #include <bitse ...

  9. [SDOI2007]游戏

    https://zybuluo.com/ysner/note/1184420 题面 题意简单,但不太好概括. 戳我 解析 不成熟想法 据题意可知,字符串字符的顺序无影响. 并且判断两个字符串能否接龙可 ...

  10. 学习XOR

    //f(x;W,c,w,b)=w*max{0, W*x+c}+b #include <iostream>#include <vector>#include <algori ...