1142 Maximal Clique (25 分)
Acliqueis a subset of vertices of an undirected graph such that every two distinct vertices in the clique are adjacent. Amaximal cliqueis a clique that cannot be extended by including one more adj...
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
思路:其实一开始没看懂题,那两个关键单词都不认识,但知道是个图论,画图就知道题意要求团了,然后暴力跑出答案即可。
AC代码:
//include <bits/stdc++.h>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <stack>
#include <time.h>
#include <string.h>
#include <vector>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <functional>
#define sdddd(x,y,z,k) scanf("%d%d%d%d", &x, &y, &z, &k)
#define sddd(x,y,z) scanf("%d%d%d", &x, &y, &z)
#define sdd(x,y) scanf("%d%d", &x, &y)
#define sd(x) scanf("%d", &x)
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define per(i,a,b) for(int i=a;i>=b;i--)
//#define mp Debug(x) printf("%d\n", &x);
#define pb push_back
#define ms(x, y) memset(x, y, sizeof x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll MOD = 1046513837;
const int maxn = 1e5 + 50;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3f;
//typedef vector<ll> vec;
//typedef vector<vec> mat;
template <class T>
inline bool scan_d(T &ret) {
char c; int sgn;
if (c = getchar(), c == EOF) return 0;
while (c != '-' && (c<'0' || c>'9')) c = getchar();
sgn = (c == '-') ? -1 : 1;
ret = (c == '-') ? 0 : (c - '0');
while (c = getchar(), c >= '0'&&c <= '9') ret = ret * 10 + (c - '0');
ret *= sgn;
return 1;
}
int n, m, k;
int edge[205][205];
int arr[205];
int main() {
cin >> n >> m;
int a, b;
rep(i, 1, m){
cin >> a >> b;
edge[a][b] = 1;
edge[b][a] = 1;
}
int tmp;
cin >> k;
set<int> st;
rep(i, 1, k){
cin >> tmp;
st.clear();
rep(j ,1 , tmp){
cin >> arr[j];
st.insert(arr[j]);
}
int flag = 1;
rep(x, 1, tmp){
rep(y, x+1, tmp){
if(edge[arr[x]][arr[y]] != 1){
flag = 0;
break;
}
}
if(!flag) break;
}
if(!flag){
cout << "Not a Clique" <<endl;
continue;
}
flag = 0;
rep(x, 1, n){
if(st.count(x)) continue;
flag = 1;
rep(y, 1, tmp){
if(edge[arr[y]][x] == 0){
flag = 0;
break;
}
}
if(flag){
break;
}
}
if(flag){
cout << "Not Maximal" <<endl;
}else
cout << "Yes" << endl;
}
return 0;
}
/*
4 0 10 6
*/
昇腾计算产业是基于昇腾系列(HUAWEI Ascend)处理器和基础软件构建的全栈 AI计算基础设施、行业应用及服务,https://devpress.csdn.net/organization/setting/general/146749包括昇腾系列处理器、系列硬件、CANN、AI计算框架、应用使能、开发工具链、管理运维工具、行业应用及服务等全产业链
更多推荐


所有评论(0)