本文共 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.
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.
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
.
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
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/