-
Notifications
You must be signed in to change notification settings - Fork 814
/
Copy path1142. Maximal Clique (25) .cpp
47 lines (47 loc) · 1.29 KB
/
1142. Maximal Clique (25) .cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include <iostream>
#include <vector>
using namespace std;
int e[210][210];
int main() {
int nv, ne, m, ta, tb, k;
scanf("%d %d", &nv, &ne);
for (int i = 0; i < ne; i++) {
scanf("%d %d", &ta, &tb);
e[ta][tb] = e[tb][ta] = 1;
}
scanf("%d", &m);
for (int i = 0; i < m; i++) {
scanf("%d", &k);
vector<int> v(k);
int hash[210] = {0}, isclique = 1, isMaximal = 1;
for (int j = 0; j < k; j++) {
scanf("%d", &v[j]);
hash[v[j]] = 1;
}
for (int j = 0; j < k; j++) {
if (isclique == 0) break;
for (int l = j + 1; l < k; l++) {
if (e[v[j]][v[l]] == 0) {
isclique = 0;
printf("Not a Clique\n");
break;
}
}
}
if (isclique == 0) continue;
for (int j = 1; j <= nv; j++) {
if (hash[j] == 0) {
for (int l = 0; l < k; l++) {
if (e[v[l]][j] == 0) break;
if (l == k - 1) isMaximal = 0;
}
}
if (isMaximal == 0) {
printf("Not Maximal\n");
break;
}
}
if (isMaximal == 1) printf("Yes\n");
}
return 0;
}