#include <bits/stdc++.h> // score: 100
using namespace std;
int clique_n;
array<bitset<10>, 10> adjmat;
vector<uint8_t> selected;
int largest_clique(int i) {
if (i == clique_n)
return selected.size();
int best = largest_clique(i+1); // skip i
bool can_take_i = true;
for (auto j : selected) {
if (!adjmat[i][j]) {
can_take_i = false;
break;
}
}
if (can_take_i) {
selected.push_back(i);
best = max(best, largest_clique(i)); // take i
selected.pop_back();
}
return best;
}
signed main() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
int n, k; cin >> n >> k;
vector<vector<int>> g(n);
vector<int> degree(n);
for (int i = 0; i < n; ++i) {
cin >> degree[i];
for (int j = 0; j < degree[i]; ++j) {
int b; cin >> b;
g[i].push_back(b);
}
}
vector<bool> removed(n);
priority_queue<pair<size_t, int>,
vector<pair<size_t, int>>,
greater<>> pq;
for (int i = 0; i < n; ++i)
pq.emplace(degree[i], i);
for (auto& v : g)
sort(v.begin(), v.end());
auto has_edge = [&](int a, int b) { return binary_search(g[a].begin(), g[a].end(), b); };
int best = 1;
while (!pq.empty()) {
auto [_, i] = pq.top();
pq.pop();
if (removed[i])
continue;
removed[i] = true;
vector<int> nbs = g[i];
nbs.erase(remove_if(nbs.begin(), nbs.end(), [&](int v){ return removed[v]; }), nbs.end());
adjmat = {};
selected.clear();
clique_n = nbs.size();
for (size_t i = 0; i < nbs.size(); ++i) {
for (size_t j = 0; j < nbs.size(); ++j) {
if (i != j)
adjmat[i][j] = has_edge(nbs[i], nbs[j]);
}
}
best = max(best, 1+largest_clique(0)); // 1+ because we always take i itself
for (auto j : nbs) {
--degree[j];
pq.emplace(degree[j], j);
}
}
cout << best << '\n';
}
Compilation message
politicaldevelopment.cpp: In function 'int main()':
politicaldevelopment.cpp:54:10: warning: decomposition declaration only available with -std=c++1z or -std=gnu++1z
auto [_, i] = pq.top();
^
politicaldevelopment.cpp:54:15: warning: unused variable '_' [-Wunused-variable]
auto [_, i] = pq.top();
^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
8 ms |
896 KB |
Output is correct |
4 |
Correct |
8 ms |
896 KB |
Output is correct |
5 |
Correct |
8 ms |
896 KB |
Output is correct |
6 |
Correct |
8 ms |
896 KB |
Output is correct |
7 |
Correct |
8 ms |
896 KB |
Output is correct |
8 |
Correct |
6 ms |
768 KB |
Output is correct |
9 |
Correct |
4 ms |
384 KB |
Output is correct |
10 |
Correct |
6 ms |
640 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
8 ms |
896 KB |
Output is correct |
4 |
Correct |
8 ms |
896 KB |
Output is correct |
5 |
Correct |
8 ms |
896 KB |
Output is correct |
6 |
Correct |
8 ms |
896 KB |
Output is correct |
7 |
Correct |
8 ms |
896 KB |
Output is correct |
8 |
Correct |
6 ms |
768 KB |
Output is correct |
9 |
Correct |
4 ms |
384 KB |
Output is correct |
10 |
Correct |
6 ms |
640 KB |
Output is correct |
11 |
Correct |
8 ms |
896 KB |
Output is correct |
12 |
Correct |
8 ms |
1024 KB |
Output is correct |
13 |
Correct |
5 ms |
384 KB |
Output is correct |
14 |
Correct |
8 ms |
896 KB |
Output is correct |
15 |
Correct |
4 ms |
384 KB |
Output is correct |
16 |
Correct |
11 ms |
896 KB |
Output is correct |
17 |
Correct |
4 ms |
384 KB |
Output is correct |
18 |
Correct |
8 ms |
896 KB |
Output is correct |
19 |
Correct |
6 ms |
640 KB |
Output is correct |
20 |
Correct |
7 ms |
896 KB |
Output is correct |
21 |
Correct |
9 ms |
1024 KB |
Output is correct |
22 |
Correct |
5 ms |
768 KB |
Output is correct |
23 |
Correct |
9 ms |
896 KB |
Output is correct |
24 |
Correct |
6 ms |
640 KB |
Output is correct |
25 |
Correct |
9 ms |
896 KB |
Output is correct |
26 |
Correct |
9 ms |
896 KB |
Output is correct |
27 |
Correct |
8 ms |
896 KB |
Output is correct |
28 |
Correct |
9 ms |
896 KB |
Output is correct |
29 |
Correct |
8 ms |
896 KB |
Output is correct |
30 |
Correct |
9 ms |
1024 KB |
Output is correct |
31 |
Correct |
9 ms |
896 KB |
Output is correct |
32 |
Correct |
9 ms |
1024 KB |
Output is correct |
33 |
Correct |
10 ms |
896 KB |
Output is correct |
34 |
Correct |
10 ms |
896 KB |
Output is correct |
35 |
Correct |
7 ms |
640 KB |
Output is correct |
36 |
Correct |
7 ms |
640 KB |
Output is correct |
37 |
Correct |
7 ms |
640 KB |
Output is correct |
38 |
Correct |
6 ms |
512 KB |
Output is correct |
39 |
Correct |
6 ms |
512 KB |
Output is correct |
40 |
Correct |
11 ms |
1152 KB |
Output is correct |
41 |
Correct |
6 ms |
512 KB |
Output is correct |
42 |
Correct |
11 ms |
1152 KB |
Output is correct |
43 |
Correct |
12 ms |
1152 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
640 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
4 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
4 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
384 KB |
Output is correct |
7 |
Correct |
5 ms |
384 KB |
Output is correct |
8 |
Correct |
5 ms |
384 KB |
Output is correct |
9 |
Correct |
5 ms |
384 KB |
Output is correct |
10 |
Correct |
5 ms |
384 KB |
Output is correct |
11 |
Correct |
193 ms |
10216 KB |
Output is correct |
12 |
Correct |
5 ms |
384 KB |
Output is correct |
13 |
Correct |
184 ms |
10088 KB |
Output is correct |
14 |
Correct |
5 ms |
384 KB |
Output is correct |
15 |
Correct |
185 ms |
10088 KB |
Output is correct |
16 |
Correct |
199 ms |
10216 KB |
Output is correct |
17 |
Correct |
183 ms |
10192 KB |
Output is correct |
18 |
Correct |
183 ms |
10088 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
8 ms |
896 KB |
Output is correct |
4 |
Correct |
8 ms |
896 KB |
Output is correct |
5 |
Correct |
8 ms |
896 KB |
Output is correct |
6 |
Correct |
8 ms |
896 KB |
Output is correct |
7 |
Correct |
8 ms |
896 KB |
Output is correct |
8 |
Correct |
6 ms |
768 KB |
Output is correct |
9 |
Correct |
4 ms |
384 KB |
Output is correct |
10 |
Correct |
6 ms |
640 KB |
Output is correct |
11 |
Correct |
8 ms |
896 KB |
Output is correct |
12 |
Correct |
8 ms |
1024 KB |
Output is correct |
13 |
Correct |
5 ms |
384 KB |
Output is correct |
14 |
Correct |
8 ms |
896 KB |
Output is correct |
15 |
Correct |
4 ms |
384 KB |
Output is correct |
16 |
Correct |
11 ms |
896 KB |
Output is correct |
17 |
Correct |
4 ms |
384 KB |
Output is correct |
18 |
Correct |
8 ms |
896 KB |
Output is correct |
19 |
Correct |
6 ms |
640 KB |
Output is correct |
20 |
Correct |
7 ms |
896 KB |
Output is correct |
21 |
Correct |
9 ms |
1024 KB |
Output is correct |
22 |
Correct |
5 ms |
768 KB |
Output is correct |
23 |
Correct |
9 ms |
896 KB |
Output is correct |
24 |
Correct |
6 ms |
640 KB |
Output is correct |
25 |
Correct |
9 ms |
896 KB |
Output is correct |
26 |
Correct |
9 ms |
896 KB |
Output is correct |
27 |
Correct |
8 ms |
896 KB |
Output is correct |
28 |
Correct |
9 ms |
896 KB |
Output is correct |
29 |
Correct |
8 ms |
896 KB |
Output is correct |
30 |
Correct |
9 ms |
1024 KB |
Output is correct |
31 |
Correct |
9 ms |
896 KB |
Output is correct |
32 |
Correct |
9 ms |
1024 KB |
Output is correct |
33 |
Correct |
10 ms |
896 KB |
Output is correct |
34 |
Correct |
10 ms |
896 KB |
Output is correct |
35 |
Correct |
7 ms |
640 KB |
Output is correct |
36 |
Correct |
7 ms |
640 KB |
Output is correct |
37 |
Correct |
7 ms |
640 KB |
Output is correct |
38 |
Correct |
6 ms |
512 KB |
Output is correct |
39 |
Correct |
6 ms |
512 KB |
Output is correct |
40 |
Correct |
11 ms |
1152 KB |
Output is correct |
41 |
Correct |
6 ms |
512 KB |
Output is correct |
42 |
Correct |
11 ms |
1152 KB |
Output is correct |
43 |
Correct |
12 ms |
1152 KB |
Output is correct |
44 |
Correct |
24 ms |
1152 KB |
Output is correct |
45 |
Correct |
4 ms |
384 KB |
Output is correct |
46 |
Correct |
11 ms |
1152 KB |
Output is correct |
47 |
Correct |
19 ms |
1664 KB |
Output is correct |
48 |
Correct |
11 ms |
1152 KB |
Output is correct |
49 |
Correct |
18 ms |
1664 KB |
Output is correct |
50 |
Correct |
19 ms |
1664 KB |
Output is correct |
51 |
Correct |
37 ms |
2556 KB |
Output is correct |
52 |
Correct |
9 ms |
896 KB |
Output is correct |
53 |
Correct |
38 ms |
2680 KB |
Output is correct |
54 |
Correct |
44 ms |
2672 KB |
Output is correct |
55 |
Correct |
8 ms |
896 KB |
Output is correct |
56 |
Correct |
8 ms |
896 KB |
Output is correct |
57 |
Correct |
6 ms |
768 KB |
Output is correct |
58 |
Correct |
34 ms |
2680 KB |
Output is correct |
59 |
Correct |
11 ms |
896 KB |
Output is correct |
60 |
Correct |
8 ms |
896 KB |
Output is correct |
61 |
Correct |
11 ms |
896 KB |
Output is correct |
62 |
Correct |
11 ms |
896 KB |
Output is correct |
63 |
Correct |
21 ms |
1152 KB |
Output is correct |
64 |
Correct |
17 ms |
1152 KB |
Output is correct |
65 |
Correct |
11 ms |
1152 KB |
Output is correct |
66 |
Correct |
11 ms |
896 KB |
Output is correct |
67 |
Correct |
23 ms |
1660 KB |
Output is correct |
68 |
Correct |
17 ms |
1152 KB |
Output is correct |
69 |
Correct |
11 ms |
1152 KB |
Output is correct |
70 |
Correct |
17 ms |
1280 KB |
Output is correct |
71 |
Correct |
23 ms |
1660 KB |
Output is correct |
72 |
Correct |
22 ms |
1660 KB |
Output is correct |
73 |
Correct |
8 ms |
896 KB |
Output is correct |
74 |
Correct |
17 ms |
1280 KB |
Output is correct |
75 |
Correct |
21 ms |
1660 KB |
Output is correct |
76 |
Correct |
14 ms |
1280 KB |
Output is correct |
77 |
Correct |
25 ms |
1792 KB |
Output is correct |
78 |
Correct |
8 ms |
896 KB |
Output is correct |
79 |
Correct |
15 ms |
1152 KB |
Output is correct |
80 |
Correct |
14 ms |
1280 KB |
Output is correct |
81 |
Correct |
25 ms |
2084 KB |
Output is correct |
82 |
Correct |
6 ms |
512 KB |
Output is correct |
83 |
Correct |
21 ms |
1152 KB |
Output is correct |
84 |
Correct |
20 ms |
1792 KB |
Output is correct |
85 |
Correct |
6 ms |
640 KB |
Output is correct |
86 |
Correct |
20 ms |
1792 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
8 ms |
896 KB |
Output is correct |
4 |
Correct |
8 ms |
896 KB |
Output is correct |
5 |
Correct |
8 ms |
896 KB |
Output is correct |
6 |
Correct |
8 ms |
896 KB |
Output is correct |
7 |
Correct |
8 ms |
896 KB |
Output is correct |
8 |
Correct |
6 ms |
768 KB |
Output is correct |
9 |
Correct |
4 ms |
384 KB |
Output is correct |
10 |
Correct |
6 ms |
640 KB |
Output is correct |
11 |
Correct |
8 ms |
896 KB |
Output is correct |
12 |
Correct |
8 ms |
1024 KB |
Output is correct |
13 |
Correct |
5 ms |
384 KB |
Output is correct |
14 |
Correct |
8 ms |
896 KB |
Output is correct |
15 |
Correct |
4 ms |
384 KB |
Output is correct |
16 |
Correct |
11 ms |
896 KB |
Output is correct |
17 |
Correct |
4 ms |
384 KB |
Output is correct |
18 |
Correct |
8 ms |
896 KB |
Output is correct |
19 |
Correct |
6 ms |
640 KB |
Output is correct |
20 |
Correct |
7 ms |
896 KB |
Output is correct |
21 |
Correct |
9 ms |
1024 KB |
Output is correct |
22 |
Correct |
5 ms |
768 KB |
Output is correct |
23 |
Correct |
9 ms |
896 KB |
Output is correct |
24 |
Correct |
6 ms |
640 KB |
Output is correct |
25 |
Correct |
9 ms |
896 KB |
Output is correct |
26 |
Correct |
9 ms |
896 KB |
Output is correct |
27 |
Correct |
8 ms |
896 KB |
Output is correct |
28 |
Correct |
9 ms |
896 KB |
Output is correct |
29 |
Correct |
8 ms |
896 KB |
Output is correct |
30 |
Correct |
9 ms |
1024 KB |
Output is correct |
31 |
Correct |
9 ms |
896 KB |
Output is correct |
32 |
Correct |
9 ms |
1024 KB |
Output is correct |
33 |
Correct |
10 ms |
896 KB |
Output is correct |
34 |
Correct |
10 ms |
896 KB |
Output is correct |
35 |
Correct |
7 ms |
640 KB |
Output is correct |
36 |
Correct |
7 ms |
640 KB |
Output is correct |
37 |
Correct |
7 ms |
640 KB |
Output is correct |
38 |
Correct |
6 ms |
512 KB |
Output is correct |
39 |
Correct |
6 ms |
512 KB |
Output is correct |
40 |
Correct |
11 ms |
1152 KB |
Output is correct |
41 |
Correct |
6 ms |
512 KB |
Output is correct |
42 |
Correct |
11 ms |
1152 KB |
Output is correct |
43 |
Correct |
12 ms |
1152 KB |
Output is correct |
44 |
Correct |
4 ms |
384 KB |
Output is correct |
45 |
Correct |
124 ms |
10088 KB |
Output is correct |
46 |
Correct |
62 ms |
5500 KB |
Output is correct |
47 |
Correct |
128 ms |
10092 KB |
Output is correct |
48 |
Correct |
125 ms |
10088 KB |
Output is correct |
49 |
Correct |
39 ms |
5496 KB |
Output is correct |
50 |
Correct |
131 ms |
10724 KB |
Output is correct |
51 |
Correct |
124 ms |
10220 KB |
Output is correct |
52 |
Correct |
41 ms |
5368 KB |
Output is correct |
53 |
Correct |
39 ms |
5368 KB |
Output is correct |
54 |
Correct |
13 ms |
2940 KB |
Output is correct |
55 |
Correct |
133 ms |
10852 KB |
Output is correct |
56 |
Correct |
30 ms |
4860 KB |
Output is correct |
57 |
Correct |
41 ms |
5368 KB |
Output is correct |
58 |
Correct |
57 ms |
5492 KB |
Output is correct |
59 |
Correct |
29 ms |
4860 KB |
Output is correct |
60 |
Correct |
36 ms |
4860 KB |
Output is correct |
61 |
Correct |
57 ms |
5444 KB |
Output is correct |
62 |
Correct |
44 ms |
5116 KB |
Output is correct |
63 |
Correct |
80 ms |
7020 KB |
Output is correct |
64 |
Correct |
30 ms |
4860 KB |
Output is correct |
65 |
Correct |
92 ms |
7280 KB |
Output is correct |
66 |
Correct |
44 ms |
5116 KB |
Output is correct |
67 |
Correct |
73 ms |
6764 KB |
Output is correct |
68 |
Correct |
87 ms |
7144 KB |
Output is correct |
69 |
Correct |
95 ms |
7412 KB |
Output is correct |
70 |
Correct |
41 ms |
5116 KB |
Output is correct |
71 |
Correct |
86 ms |
7148 KB |
Output is correct |
72 |
Correct |
70 ms |
6768 KB |
Output is correct |
73 |
Correct |
100 ms |
7532 KB |
Output is correct |
74 |
Correct |
45 ms |
5116 KB |
Output is correct |
75 |
Correct |
39 ms |
3700 KB |
Output is correct |
76 |
Correct |
72 ms |
6832 KB |
Output is correct |
77 |
Correct |
98 ms |
7532 KB |
Output is correct |
78 |
Correct |
51 ms |
3952 KB |
Output is correct |
79 |
Correct |
39 ms |
3704 KB |
Output is correct |
80 |
Correct |
21 ms |
2172 KB |
Output is correct |
81 |
Correct |
51 ms |
3952 KB |
Output is correct |
82 |
Correct |
77 ms |
6768 KB |
Output is correct |
83 |
Correct |
21 ms |
2080 KB |
Output is correct |
84 |
Correct |
77 ms |
6768 KB |
Output is correct |