#include "bits/extc++.h"
using namespace std;
template <typename T>
void dbgh(const T& t) {
cerr << t << endl;
}
template <typename T, typename... U>
void dbgh(const T& t, const U&... u) {
cerr << t << " | ";
dbgh(u...);
}
#ifdef DEBUG
#define dbg(...) \
cerr << "L" << __LINE__ << " [" << #__VA_ARGS__ << "]" \
<< ": "; \
dbgh(__VA_ARGS__)
#else
#define cerr \
if (false) \
cerr
#define dbg(...)
#endif
#define endl "\n"
#define long int64_t
#define sz(x) int((x).size())
template <typename T>
using min_pq = priority_queue<T, vector<T>, greater<T>>;
bool on(int msk, int bit) {
return (msk >> bit) & 1;
}
int clique(const vector<vector<bool>>& graph) {
int n = sz(graph);
int dp[1 << n];
for (int i = (1 << n) - 1; i >= 0; i--) {
dp[i] = __builtin_popcount(i);
for (int j = 0; j < n; j++) {
if (!on(i, j)) {
for (int k = 0; k < n; k++) {
if (on(i, k) && !graph[j][k]) {
goto loop;
}
}
dp[i] = max(dp[i], dp[i | (1 << j)]);
loop:;
}
}
}
return dp[0];
}
void solve() {
int n, k;
cin >> n >> k;
vector<int> graph[n];
for (auto& a : graph) {
int m;
cin >> m;
a.resize(m);
for (auto& b : a) {
cin >> b;
}
sort(begin(a), end(a));
}
bool del[n] {};
int deg[n] {};
for (int i = 0; i < n; i++) {
deg[i] = sz(graph[i]);
}
min_pq<pair<int, int>> pq;
for (int i = 0; i < n; i++) {
pq.emplace(deg[i], i);
}
int ans = 0;
for (int _ = 0; _ < n; _++) {
int u;
while (true) {
auto [d, v] = pq.top();
pq.pop();
if (!del[v] && deg[v] == d) {
u = v;
break;
}
}
dbg(u);
del[u] = true;
for (auto& a : graph[u]) {
deg[a]--;
pq.emplace(deg[a], a);
}
vector<int> cur = {u};
for (auto& a : graph[u]) {
if (!del[a]) {
dbg(a);
cur.push_back(a);
}
}
int m = sz(cur);
vector<vector<bool>> cg(m, vector<bool> (m));
for (int i = 0; i < m; i++) {
for (int j = i + 1; j < m; j++) {
if (binary_search(begin(graph[cur[i]]), end(graph[cur[i]]), cur[j])) {
cg[i][j] = cg[j][i] = true;
}
}
}
ans = max(ans, clique(cg));
}
cout << ans << endl;
}
int main() {
cin.tie(nullptr);
ios_base::sync_with_stdio(false);
cin.exceptions(ios::failbit);
solve();
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
5 ms |
596 KB |
Output is correct |
4 |
Correct |
4 ms |
736 KB |
Output is correct |
5 |
Correct |
4 ms |
852 KB |
Output is correct |
6 |
Correct |
4 ms |
724 KB |
Output is correct |
7 |
Correct |
4 ms |
724 KB |
Output is correct |
8 |
Correct |
2 ms |
468 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
2 ms |
468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
5 ms |
596 KB |
Output is correct |
4 |
Correct |
4 ms |
736 KB |
Output is correct |
5 |
Correct |
4 ms |
852 KB |
Output is correct |
6 |
Correct |
4 ms |
724 KB |
Output is correct |
7 |
Correct |
4 ms |
724 KB |
Output is correct |
8 |
Correct |
2 ms |
468 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
2 ms |
468 KB |
Output is correct |
11 |
Correct |
4 ms |
852 KB |
Output is correct |
12 |
Correct |
4 ms |
804 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
5 ms |
724 KB |
Output is correct |
15 |
Correct |
6 ms |
212 KB |
Output is correct |
16 |
Correct |
4 ms |
724 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
4 ms |
724 KB |
Output is correct |
19 |
Correct |
2 ms |
468 KB |
Output is correct |
20 |
Correct |
3 ms |
596 KB |
Output is correct |
21 |
Correct |
3 ms |
724 KB |
Output is correct |
22 |
Correct |
2 ms |
468 KB |
Output is correct |
23 |
Correct |
5 ms |
728 KB |
Output is correct |
24 |
Correct |
2 ms |
576 KB |
Output is correct |
25 |
Correct |
5 ms |
724 KB |
Output is correct |
26 |
Correct |
8 ms |
728 KB |
Output is correct |
27 |
Correct |
4 ms |
780 KB |
Output is correct |
28 |
Correct |
5 ms |
728 KB |
Output is correct |
29 |
Correct |
5 ms |
784 KB |
Output is correct |
30 |
Correct |
6 ms |
820 KB |
Output is correct |
31 |
Correct |
6 ms |
804 KB |
Output is correct |
32 |
Correct |
6 ms |
724 KB |
Output is correct |
33 |
Correct |
5 ms |
800 KB |
Output is correct |
34 |
Correct |
5 ms |
724 KB |
Output is correct |
35 |
Correct |
3 ms |
468 KB |
Output is correct |
36 |
Correct |
3 ms |
468 KB |
Output is correct |
37 |
Correct |
3 ms |
468 KB |
Output is correct |
38 |
Correct |
2 ms |
468 KB |
Output is correct |
39 |
Correct |
2 ms |
468 KB |
Output is correct |
40 |
Correct |
8 ms |
952 KB |
Output is correct |
41 |
Correct |
2 ms |
468 KB |
Output is correct |
42 |
Correct |
7 ms |
852 KB |
Output is correct |
43 |
Correct |
8 ms |
844 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
468 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
324 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
320 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
323 ms |
8800 KB |
Output is correct |
12 |
Correct |
1 ms |
320 KB |
Output is correct |
13 |
Correct |
331 ms |
8884 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
299 ms |
8788 KB |
Output is correct |
16 |
Correct |
336 ms |
8836 KB |
Output is correct |
17 |
Correct |
319 ms |
8876 KB |
Output is correct |
18 |
Correct |
371 ms |
8792 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
5 ms |
596 KB |
Output is correct |
4 |
Correct |
4 ms |
736 KB |
Output is correct |
5 |
Correct |
4 ms |
852 KB |
Output is correct |
6 |
Correct |
4 ms |
724 KB |
Output is correct |
7 |
Correct |
4 ms |
724 KB |
Output is correct |
8 |
Correct |
2 ms |
468 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
2 ms |
468 KB |
Output is correct |
11 |
Correct |
4 ms |
852 KB |
Output is correct |
12 |
Correct |
4 ms |
804 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
5 ms |
724 KB |
Output is correct |
15 |
Correct |
6 ms |
212 KB |
Output is correct |
16 |
Correct |
4 ms |
724 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
4 ms |
724 KB |
Output is correct |
19 |
Correct |
2 ms |
468 KB |
Output is correct |
20 |
Correct |
3 ms |
596 KB |
Output is correct |
21 |
Correct |
3 ms |
724 KB |
Output is correct |
22 |
Correct |
2 ms |
468 KB |
Output is correct |
23 |
Correct |
5 ms |
728 KB |
Output is correct |
24 |
Correct |
2 ms |
576 KB |
Output is correct |
25 |
Correct |
5 ms |
724 KB |
Output is correct |
26 |
Correct |
8 ms |
728 KB |
Output is correct |
27 |
Correct |
4 ms |
780 KB |
Output is correct |
28 |
Correct |
5 ms |
728 KB |
Output is correct |
29 |
Correct |
5 ms |
784 KB |
Output is correct |
30 |
Correct |
6 ms |
820 KB |
Output is correct |
31 |
Correct |
6 ms |
804 KB |
Output is correct |
32 |
Correct |
6 ms |
724 KB |
Output is correct |
33 |
Correct |
5 ms |
800 KB |
Output is correct |
34 |
Correct |
5 ms |
724 KB |
Output is correct |
35 |
Correct |
3 ms |
468 KB |
Output is correct |
36 |
Correct |
3 ms |
468 KB |
Output is correct |
37 |
Correct |
3 ms |
468 KB |
Output is correct |
38 |
Correct |
2 ms |
468 KB |
Output is correct |
39 |
Correct |
2 ms |
468 KB |
Output is correct |
40 |
Correct |
8 ms |
952 KB |
Output is correct |
41 |
Correct |
2 ms |
468 KB |
Output is correct |
42 |
Correct |
7 ms |
852 KB |
Output is correct |
43 |
Correct |
8 ms |
844 KB |
Output is correct |
44 |
Correct |
110 ms |
988 KB |
Output is correct |
45 |
Correct |
1 ms |
212 KB |
Output is correct |
46 |
Correct |
8 ms |
864 KB |
Output is correct |
47 |
Correct |
20 ms |
1236 KB |
Output is correct |
48 |
Correct |
8 ms |
872 KB |
Output is correct |
49 |
Correct |
17 ms |
1264 KB |
Output is correct |
50 |
Correct |
19 ms |
1236 KB |
Output is correct |
51 |
Correct |
211 ms |
1840 KB |
Output is correct |
52 |
Correct |
4 ms |
852 KB |
Output is correct |
53 |
Correct |
441 ms |
1956 KB |
Output is correct |
54 |
Correct |
470 ms |
1944 KB |
Output is correct |
55 |
Correct |
4 ms |
724 KB |
Output is correct |
56 |
Correct |
4 ms |
852 KB |
Output is correct |
57 |
Correct |
2 ms |
468 KB |
Output is correct |
58 |
Correct |
440 ms |
1948 KB |
Output is correct |
59 |
Correct |
7 ms |
724 KB |
Output is correct |
60 |
Correct |
4 ms |
716 KB |
Output is correct |
61 |
Correct |
8 ms |
724 KB |
Output is correct |
62 |
Correct |
7 ms |
808 KB |
Output is correct |
63 |
Correct |
99 ms |
888 KB |
Output is correct |
64 |
Correct |
46 ms |
956 KB |
Output is correct |
65 |
Correct |
8 ms |
856 KB |
Output is correct |
66 |
Correct |
7 ms |
716 KB |
Output is correct |
67 |
Correct |
52 ms |
1324 KB |
Output is correct |
68 |
Correct |
41 ms |
880 KB |
Output is correct |
69 |
Correct |
7 ms |
848 KB |
Output is correct |
70 |
Correct |
19 ms |
1108 KB |
Output is correct |
71 |
Correct |
54 ms |
1232 KB |
Output is correct |
72 |
Correct |
38 ms |
1300 KB |
Output is correct |
73 |
Correct |
4 ms |
720 KB |
Output is correct |
74 |
Correct |
17 ms |
1120 KB |
Output is correct |
75 |
Correct |
35 ms |
1336 KB |
Output is correct |
76 |
Correct |
9 ms |
980 KB |
Output is correct |
77 |
Correct |
73 ms |
1408 KB |
Output is correct |
78 |
Correct |
5 ms |
720 KB |
Output is correct |
79 |
Correct |
38 ms |
856 KB |
Output is correct |
80 |
Correct |
10 ms |
980 KB |
Output is correct |
81 |
Correct |
73 ms |
1344 KB |
Output is correct |
82 |
Correct |
2 ms |
468 KB |
Output is correct |
83 |
Correct |
37 ms |
860 KB |
Output is correct |
84 |
Correct |
31 ms |
1244 KB |
Output is correct |
85 |
Correct |
2 ms |
468 KB |
Output is correct |
86 |
Correct |
34 ms |
1276 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
5 ms |
596 KB |
Output is correct |
4 |
Correct |
4 ms |
736 KB |
Output is correct |
5 |
Correct |
4 ms |
852 KB |
Output is correct |
6 |
Correct |
4 ms |
724 KB |
Output is correct |
7 |
Correct |
4 ms |
724 KB |
Output is correct |
8 |
Correct |
2 ms |
468 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
2 ms |
468 KB |
Output is correct |
11 |
Correct |
4 ms |
852 KB |
Output is correct |
12 |
Correct |
4 ms |
804 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
5 ms |
724 KB |
Output is correct |
15 |
Correct |
6 ms |
212 KB |
Output is correct |
16 |
Correct |
4 ms |
724 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
4 ms |
724 KB |
Output is correct |
19 |
Correct |
2 ms |
468 KB |
Output is correct |
20 |
Correct |
3 ms |
596 KB |
Output is correct |
21 |
Correct |
3 ms |
724 KB |
Output is correct |
22 |
Correct |
2 ms |
468 KB |
Output is correct |
23 |
Correct |
5 ms |
728 KB |
Output is correct |
24 |
Correct |
2 ms |
576 KB |
Output is correct |
25 |
Correct |
5 ms |
724 KB |
Output is correct |
26 |
Correct |
8 ms |
728 KB |
Output is correct |
27 |
Correct |
4 ms |
780 KB |
Output is correct |
28 |
Correct |
5 ms |
728 KB |
Output is correct |
29 |
Correct |
5 ms |
784 KB |
Output is correct |
30 |
Correct |
6 ms |
820 KB |
Output is correct |
31 |
Correct |
6 ms |
804 KB |
Output is correct |
32 |
Correct |
6 ms |
724 KB |
Output is correct |
33 |
Correct |
5 ms |
800 KB |
Output is correct |
34 |
Correct |
5 ms |
724 KB |
Output is correct |
35 |
Correct |
3 ms |
468 KB |
Output is correct |
36 |
Correct |
3 ms |
468 KB |
Output is correct |
37 |
Correct |
3 ms |
468 KB |
Output is correct |
38 |
Correct |
2 ms |
468 KB |
Output is correct |
39 |
Correct |
2 ms |
468 KB |
Output is correct |
40 |
Correct |
8 ms |
952 KB |
Output is correct |
41 |
Correct |
2 ms |
468 KB |
Output is correct |
42 |
Correct |
7 ms |
852 KB |
Output is correct |
43 |
Correct |
8 ms |
844 KB |
Output is correct |
44 |
Correct |
1 ms |
212 KB |
Output is correct |
45 |
Correct |
137 ms |
7604 KB |
Output is correct |
46 |
Correct |
59 ms |
5468 KB |
Output is correct |
47 |
Correct |
120 ms |
7604 KB |
Output is correct |
48 |
Correct |
121 ms |
7564 KB |
Output is correct |
49 |
Correct |
51 ms |
5264 KB |
Output is correct |
50 |
Correct |
142 ms |
8616 KB |
Output is correct |
51 |
Correct |
111 ms |
7544 KB |
Output is correct |
52 |
Correct |
36 ms |
4764 KB |
Output is correct |
53 |
Correct |
37 ms |
5304 KB |
Output is correct |
54 |
Correct |
13 ms |
2392 KB |
Output is correct |
55 |
Correct |
151 ms |
8576 KB |
Output is correct |
56 |
Correct |
30 ms |
4308 KB |
Output is correct |
57 |
Correct |
36 ms |
4680 KB |
Output is correct |
58 |
Correct |
57 ms |
4836 KB |
Output is correct |
59 |
Correct |
34 ms |
4328 KB |
Output is correct |
60 |
Correct |
36 ms |
4304 KB |
Output is correct |
61 |
Correct |
62 ms |
4820 KB |
Output is correct |
62 |
Correct |
42 ms |
4568 KB |
Output is correct |
63 |
Correct |
68 ms |
5496 KB |
Output is correct |
64 |
Correct |
31 ms |
4332 KB |
Output is correct |
65 |
Correct |
87 ms |
5936 KB |
Output is correct |
66 |
Correct |
58 ms |
4524 KB |
Output is correct |
67 |
Correct |
84 ms |
5532 KB |
Output is correct |
68 |
Correct |
81 ms |
5744 KB |
Output is correct |
69 |
Correct |
98 ms |
5940 KB |
Output is correct |
70 |
Correct |
43 ms |
4556 KB |
Output is correct |
71 |
Correct |
85 ms |
5808 KB |
Output is correct |
72 |
Correct |
71 ms |
5540 KB |
Output is correct |
73 |
Correct |
88 ms |
6084 KB |
Output is correct |
74 |
Correct |
38 ms |
4516 KB |
Output is correct |
75 |
Correct |
35 ms |
2924 KB |
Output is correct |
76 |
Correct |
84 ms |
5648 KB |
Output is correct |
77 |
Correct |
97 ms |
6052 KB |
Output is correct |
78 |
Correct |
45 ms |
3392 KB |
Output is correct |
79 |
Correct |
41 ms |
2924 KB |
Output is correct |
80 |
Correct |
16 ms |
1816 KB |
Output is correct |
81 |
Correct |
48 ms |
3264 KB |
Output is correct |
82 |
Correct |
84 ms |
5580 KB |
Output is correct |
83 |
Correct |
15 ms |
1748 KB |
Output is correct |
84 |
Correct |
69 ms |
5596 KB |
Output is correct |