#include <bits/stdc++.h>
int main() {
int N, K;
std::cin >> N >> K;
std::vector<int> D(N);
std::vector<std::vector<int>> E(N);
for (int i = 0; i < N; ++i) {
std::cin >> D[i];
E[i].resize(D[i]);
for (auto &e : E[i]) {
std::cin >> e;
}
}
int answer = 0;
if (N <= 5000 or K <= 5) {
// Group 1, 2, 4, 5
std::vector<std::unordered_set<int>> S(N);
for (int i = 0; i < N; ++i) {
for (auto &e : E[i]) {
S[i].insert(e);
}
}
std::set<std::pair<int, int>> group_size;
for (int i = 0; i < N; ++i) {
group_size.insert({D[i], i});
}
while (not group_size.empty()) {
const auto [s, f] = *group_size.begin();
group_size.erase(group_size.begin());
// step 1 : brute force
assert(s < K);
std::vector<std::vector<bool>> table(s, std::vector<bool>(s));
int i1 = 0;
for (const int e : S[f]) {
int i2 = 0;
for (const int e2 : S[f]) {
if (S[e].find(e2) != S[e].end()) {
table[i1][i2] = true;
}
++i2;
}
++i1;
}
std::vector<bool> dp(1 << s);
dp[0] = true;
for (int state = 0; state < (1 << s); ++state) {
if (not dp[state]) {
continue;
}
answer = std::max(answer, __builtin_popcount(state) + 1);
for (int new_bit = 0; new_bit < s; ++new_bit) {
if ((state & (1 << new_bit)) or dp[state | (1 << new_bit)]) {
continue;
}
bool ok = true;
for (int i = 0; i < s; ++i) {
if (state & (1 << i)) {
if (not table[i][new_bit]) {
ok = false;
break;
}
}
}
if (ok) {
dp[state | (1 << new_bit)] = true;
}
}
}
// step 2 : update
for (const int e : S[f]) {
S[e].erase(f);
const auto itr = group_size.find({D[e], e});
group_size.erase(itr);
group_size.insert({--D[e], e});
}
}
std::cout << answer << std::endl;
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
8 ms |
1976 KB |
Output is correct |
4 |
Correct |
7 ms |
2004 KB |
Output is correct |
5 |
Correct |
9 ms |
2004 KB |
Output is correct |
6 |
Correct |
9 ms |
2020 KB |
Output is correct |
7 |
Correct |
9 ms |
1968 KB |
Output is correct |
8 |
Correct |
2 ms |
852 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
2 ms |
852 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
8 ms |
1976 KB |
Output is correct |
4 |
Correct |
7 ms |
2004 KB |
Output is correct |
5 |
Correct |
9 ms |
2004 KB |
Output is correct |
6 |
Correct |
9 ms |
2020 KB |
Output is correct |
7 |
Correct |
9 ms |
1968 KB |
Output is correct |
8 |
Correct |
2 ms |
852 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
2 ms |
852 KB |
Output is correct |
11 |
Correct |
7 ms |
2004 KB |
Output is correct |
12 |
Correct |
7 ms |
2024 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
8 ms |
2084 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
9 ms |
2004 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
9 ms |
2004 KB |
Output is correct |
19 |
Correct |
2 ms |
852 KB |
Output is correct |
20 |
Correct |
6 ms |
1748 KB |
Output is correct |
21 |
Correct |
6 ms |
1748 KB |
Output is correct |
22 |
Correct |
2 ms |
944 KB |
Output is correct |
23 |
Correct |
10 ms |
2004 KB |
Output is correct |
24 |
Correct |
2 ms |
852 KB |
Output is correct |
25 |
Correct |
10 ms |
2004 KB |
Output is correct |
26 |
Correct |
9 ms |
1932 KB |
Output is correct |
27 |
Correct |
8 ms |
1980 KB |
Output is correct |
28 |
Correct |
9 ms |
2004 KB |
Output is correct |
29 |
Correct |
10 ms |
2004 KB |
Output is correct |
30 |
Correct |
12 ms |
2184 KB |
Output is correct |
31 |
Correct |
10 ms |
2112 KB |
Output is correct |
32 |
Correct |
10 ms |
2132 KB |
Output is correct |
33 |
Correct |
11 ms |
2132 KB |
Output is correct |
34 |
Correct |
10 ms |
2084 KB |
Output is correct |
35 |
Correct |
6 ms |
1216 KB |
Output is correct |
36 |
Correct |
6 ms |
1200 KB |
Output is correct |
37 |
Correct |
5 ms |
1116 KB |
Output is correct |
38 |
Correct |
3 ms |
724 KB |
Output is correct |
39 |
Correct |
4 ms |
724 KB |
Output is correct |
40 |
Correct |
14 ms |
2320 KB |
Output is correct |
41 |
Correct |
5 ms |
724 KB |
Output is correct |
42 |
Correct |
14 ms |
2388 KB |
Output is correct |
43 |
Correct |
14 ms |
2312 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
852 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
300 KB |
Output is correct |
6 |
Correct |
1 ms |
300 KB |
Output is correct |
7 |
Correct |
1 ms |
300 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 |
296 KB |
Output is correct |
11 |
Incorrect |
135 ms |
6600 KB |
Output isn't correct |
12 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
8 ms |
1976 KB |
Output is correct |
4 |
Correct |
7 ms |
2004 KB |
Output is correct |
5 |
Correct |
9 ms |
2004 KB |
Output is correct |
6 |
Correct |
9 ms |
2020 KB |
Output is correct |
7 |
Correct |
9 ms |
1968 KB |
Output is correct |
8 |
Correct |
2 ms |
852 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
2 ms |
852 KB |
Output is correct |
11 |
Correct |
7 ms |
2004 KB |
Output is correct |
12 |
Correct |
7 ms |
2024 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
8 ms |
2084 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
9 ms |
2004 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
9 ms |
2004 KB |
Output is correct |
19 |
Correct |
2 ms |
852 KB |
Output is correct |
20 |
Correct |
6 ms |
1748 KB |
Output is correct |
21 |
Correct |
6 ms |
1748 KB |
Output is correct |
22 |
Correct |
2 ms |
944 KB |
Output is correct |
23 |
Correct |
10 ms |
2004 KB |
Output is correct |
24 |
Correct |
2 ms |
852 KB |
Output is correct |
25 |
Correct |
10 ms |
2004 KB |
Output is correct |
26 |
Correct |
9 ms |
1932 KB |
Output is correct |
27 |
Correct |
8 ms |
1980 KB |
Output is correct |
28 |
Correct |
9 ms |
2004 KB |
Output is correct |
29 |
Correct |
10 ms |
2004 KB |
Output is correct |
30 |
Correct |
12 ms |
2184 KB |
Output is correct |
31 |
Correct |
10 ms |
2112 KB |
Output is correct |
32 |
Correct |
10 ms |
2132 KB |
Output is correct |
33 |
Correct |
11 ms |
2132 KB |
Output is correct |
34 |
Correct |
10 ms |
2084 KB |
Output is correct |
35 |
Correct |
6 ms |
1216 KB |
Output is correct |
36 |
Correct |
6 ms |
1200 KB |
Output is correct |
37 |
Correct |
5 ms |
1116 KB |
Output is correct |
38 |
Correct |
3 ms |
724 KB |
Output is correct |
39 |
Correct |
4 ms |
724 KB |
Output is correct |
40 |
Correct |
14 ms |
2320 KB |
Output is correct |
41 |
Correct |
5 ms |
724 KB |
Output is correct |
42 |
Correct |
14 ms |
2388 KB |
Output is correct |
43 |
Correct |
14 ms |
2312 KB |
Output is correct |
44 |
Correct |
33 ms |
3168 KB |
Output is correct |
45 |
Correct |
0 ms |
212 KB |
Output is correct |
46 |
Correct |
14 ms |
2284 KB |
Output is correct |
47 |
Correct |
27 ms |
3276 KB |
Output is correct |
48 |
Correct |
14 ms |
2396 KB |
Output is correct |
49 |
Correct |
30 ms |
3256 KB |
Output is correct |
50 |
Correct |
32 ms |
3128 KB |
Output is correct |
51 |
Correct |
63 ms |
5156 KB |
Output is correct |
52 |
Correct |
10 ms |
2004 KB |
Output is correct |
53 |
Correct |
52 ms |
5452 KB |
Output is correct |
54 |
Correct |
63 ms |
5612 KB |
Output is correct |
55 |
Correct |
9 ms |
2004 KB |
Output is correct |
56 |
Correct |
7 ms |
2004 KB |
Output is correct |
57 |
Correct |
2 ms |
852 KB |
Output is correct |
58 |
Correct |
47 ms |
5500 KB |
Output is correct |
59 |
Correct |
15 ms |
2388 KB |
Output is correct |
60 |
Correct |
9 ms |
2116 KB |
Output is correct |
61 |
Correct |
13 ms |
2388 KB |
Output is correct |
62 |
Correct |
15 ms |
2348 KB |
Output is correct |
63 |
Correct |
32 ms |
3120 KB |
Output is correct |
64 |
Correct |
23 ms |
2900 KB |
Output is correct |
65 |
Correct |
13 ms |
2260 KB |
Output is correct |
66 |
Correct |
12 ms |
2348 KB |
Output is correct |
67 |
Correct |
33 ms |
3604 KB |
Output is correct |
68 |
Correct |
30 ms |
2996 KB |
Output is correct |
69 |
Correct |
12 ms |
2260 KB |
Output is correct |
70 |
Correct |
24 ms |
2972 KB |
Output is correct |
71 |
Correct |
33 ms |
3512 KB |
Output is correct |
72 |
Correct |
31 ms |
3452 KB |
Output is correct |
73 |
Correct |
8 ms |
1976 KB |
Output is correct |
74 |
Correct |
23 ms |
3028 KB |
Output is correct |
75 |
Correct |
30 ms |
3480 KB |
Output is correct |
76 |
Correct |
17 ms |
2636 KB |
Output is correct |
77 |
Correct |
42 ms |
3956 KB |
Output is correct |
78 |
Correct |
9 ms |
2004 KB |
Output is correct |
79 |
Correct |
18 ms |
2072 KB |
Output is correct |
80 |
Correct |
16 ms |
2648 KB |
Output is correct |
81 |
Correct |
38 ms |
4032 KB |
Output is correct |
82 |
Correct |
4 ms |
764 KB |
Output is correct |
83 |
Correct |
18 ms |
2132 KB |
Output is correct |
84 |
Correct |
28 ms |
3256 KB |
Output is correct |
85 |
Correct |
3 ms |
724 KB |
Output is correct |
86 |
Correct |
31 ms |
3240 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
8 ms |
1976 KB |
Output is correct |
4 |
Correct |
7 ms |
2004 KB |
Output is correct |
5 |
Correct |
9 ms |
2004 KB |
Output is correct |
6 |
Correct |
9 ms |
2020 KB |
Output is correct |
7 |
Correct |
9 ms |
1968 KB |
Output is correct |
8 |
Correct |
2 ms |
852 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
2 ms |
852 KB |
Output is correct |
11 |
Correct |
7 ms |
2004 KB |
Output is correct |
12 |
Correct |
7 ms |
2024 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
8 ms |
2084 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
9 ms |
2004 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
9 ms |
2004 KB |
Output is correct |
19 |
Correct |
2 ms |
852 KB |
Output is correct |
20 |
Correct |
6 ms |
1748 KB |
Output is correct |
21 |
Correct |
6 ms |
1748 KB |
Output is correct |
22 |
Correct |
2 ms |
944 KB |
Output is correct |
23 |
Correct |
10 ms |
2004 KB |
Output is correct |
24 |
Correct |
2 ms |
852 KB |
Output is correct |
25 |
Correct |
10 ms |
2004 KB |
Output is correct |
26 |
Correct |
9 ms |
1932 KB |
Output is correct |
27 |
Correct |
8 ms |
1980 KB |
Output is correct |
28 |
Correct |
9 ms |
2004 KB |
Output is correct |
29 |
Correct |
10 ms |
2004 KB |
Output is correct |
30 |
Correct |
12 ms |
2184 KB |
Output is correct |
31 |
Correct |
10 ms |
2112 KB |
Output is correct |
32 |
Correct |
10 ms |
2132 KB |
Output is correct |
33 |
Correct |
11 ms |
2132 KB |
Output is correct |
34 |
Correct |
10 ms |
2084 KB |
Output is correct |
35 |
Correct |
6 ms |
1216 KB |
Output is correct |
36 |
Correct |
6 ms |
1200 KB |
Output is correct |
37 |
Correct |
5 ms |
1116 KB |
Output is correct |
38 |
Correct |
3 ms |
724 KB |
Output is correct |
39 |
Correct |
4 ms |
724 KB |
Output is correct |
40 |
Correct |
14 ms |
2320 KB |
Output is correct |
41 |
Correct |
5 ms |
724 KB |
Output is correct |
42 |
Correct |
14 ms |
2388 KB |
Output is correct |
43 |
Correct |
14 ms |
2312 KB |
Output is correct |
44 |
Correct |
0 ms |
212 KB |
Output is correct |
45 |
Correct |
253 ms |
25620 KB |
Output is correct |
46 |
Correct |
135 ms |
19832 KB |
Output is correct |
47 |
Correct |
250 ms |
25576 KB |
Output is correct |
48 |
Correct |
253 ms |
25560 KB |
Output is correct |
49 |
Correct |
96 ms |
18388 KB |
Output is correct |
50 |
Correct |
247 ms |
32156 KB |
Output is correct |
51 |
Correct |
257 ms |
25724 KB |
Output is correct |
52 |
Correct |
95 ms |
18188 KB |
Output is correct |
53 |
Correct |
87 ms |
18436 KB |
Output is correct |
54 |
Correct |
20 ms |
6764 KB |
Output is correct |
55 |
Correct |
279 ms |
32232 KB |
Output is correct |
56 |
Correct |
70 ms |
15692 KB |
Output is correct |
57 |
Correct |
93 ms |
18128 KB |
Output is correct |
58 |
Correct |
118 ms |
19436 KB |
Output is correct |
59 |
Correct |
65 ms |
15644 KB |
Output is correct |
60 |
Correct |
67 ms |
15844 KB |
Output is correct |
61 |
Correct |
121 ms |
19400 KB |
Output is correct |
62 |
Correct |
88 ms |
17520 KB |
Output is correct |
63 |
Correct |
161 ms |
20408 KB |
Output is correct |
64 |
Correct |
63 ms |
15688 KB |
Output is correct |
65 |
Correct |
184 ms |
22280 KB |
Output is correct |
66 |
Correct |
90 ms |
17612 KB |
Output is correct |
67 |
Correct |
156 ms |
20300 KB |
Output is correct |
68 |
Correct |
176 ms |
21848 KB |
Output is correct |
69 |
Correct |
189 ms |
22364 KB |
Output is correct |
70 |
Correct |
117 ms |
17492 KB |
Output is correct |
71 |
Correct |
177 ms |
21836 KB |
Output is correct |
72 |
Correct |
145 ms |
20532 KB |
Output is correct |
73 |
Correct |
213 ms |
23516 KB |
Output is correct |
74 |
Correct |
98 ms |
17484 KB |
Output is correct |
75 |
Correct |
87 ms |
10612 KB |
Output is correct |
76 |
Correct |
144 ms |
20524 KB |
Output is correct |
77 |
Correct |
205 ms |
23524 KB |
Output is correct |
78 |
Correct |
95 ms |
11820 KB |
Output is correct |
79 |
Correct |
75 ms |
10572 KB |
Output is correct |
80 |
Correct |
33 ms |
5772 KB |
Output is correct |
81 |
Correct |
95 ms |
11784 KB |
Output is correct |
82 |
Correct |
171 ms |
21324 KB |
Output is correct |
83 |
Correct |
40 ms |
5752 KB |
Output is correct |
84 |
Correct |
165 ms |
21288 KB |
Output is correct |