#include <bits/stdc++.h>
using namespace std;
const int MAX_N_SMALL = 5005;
const int MAX_N_BIG = 50005;
bool adj[MAX_N_SMALL][MAX_N_SMALL] = {};
struct SmallKSolution {
int solve(int N, int K, vector<vector<int>> G) {
if (K == 1) {
return 1;
}
bool good = false;
for (int i = 0; i < N; i++) {
good |= !G[i].empty();
}
if (K == 2) {
return 1 + (int)good;
}
for (int i = 0; i < N; i++) {
for (int j : G[i]) {
adj[i][j] = true;
}
}
for (int i = 0; i < N; i++)
for (int j : G[i])
for (int k : G[j])
if (adj[i][k])
return 3;
return 1 + (int)good;
}
};
struct SmallMaxDegreeSolution {
int solve(int N, int K, vector<vector<int>> G) {
vector<int> pos(N, -1);
int ans = 0;
for (int i = 0; i < N; i++) {
int D = (int)G[i].size();
for (int j = 0; j < D; j++) {
pos[G[i][j]] = j + 1;
}
pos[i] = 0;
vector<int> mask(D + 1);
mask[0] = (1 << (D + 1)) - 1;
for (int j : G[i]) {
mask[pos[j]] |= 1 << pos[j];
for (int k : G[j]) {
if (pos[k] != -1) {
mask[pos[j]] |= 1 << pos[k];
}
}
}
for (int clique = 0; clique < (1 << D); clique++) {
int msk = mask[0];
for (int j = 0; j < D; j++) {
if ((clique >> j) & 1) {
msk &= mask[j + 1];
}
}
if (((clique << 1) | 1) == msk) {
ans = max(ans, __builtin_popcount(clique) + 1);
}
}
pos[i] = -1;
for (int j = 0; j < D; j++) {
pos[G[i][j]] = -1;
}
}
return ans;
}
};
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
int N, K;
cin >> N >> K;
vector<vector<int>> G(N);
for (int i = 0; i < N; i++) {
int D;
cin >> D;
G[i].resize(D);
for (int j = 0; j < D; j++) {
cin >> G[i][j];
}
}
int max_degree = 0;
for (int i = 0; i < N; i++) {
max_degree = max(max_degree, (int)G[i].size());
}
if (max_degree > 10) {
cout << SmallKSolution().solve(N, K, G) << "\n";
} else {
cout << SmallMaxDegreeSolution().solve(N, K, G) << "\n";
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
2 ms |
852 KB |
Output is correct |
4 |
Correct |
1 ms |
852 KB |
Output is correct |
5 |
Correct |
2 ms |
852 KB |
Output is correct |
6 |
Correct |
2 ms |
852 KB |
Output is correct |
7 |
Correct |
2 ms |
852 KB |
Output is correct |
8 |
Correct |
1 ms |
468 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
2 ms |
852 KB |
Output is correct |
4 |
Correct |
1 ms |
852 KB |
Output is correct |
5 |
Correct |
2 ms |
852 KB |
Output is correct |
6 |
Correct |
2 ms |
852 KB |
Output is correct |
7 |
Correct |
2 ms |
852 KB |
Output is correct |
8 |
Correct |
1 ms |
468 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
468 KB |
Output is correct |
11 |
Correct |
2 ms |
852 KB |
Output is correct |
12 |
Correct |
27 ms |
21012 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
28 ms |
21016 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
10 ms |
18952 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
10 ms |
18644 KB |
Output is correct |
19 |
Correct |
1 ms |
596 KB |
Output is correct |
20 |
Correct |
2 ms |
852 KB |
Output is correct |
21 |
Correct |
1 ms |
852 KB |
Output is correct |
22 |
Correct |
1 ms |
468 KB |
Output is correct |
23 |
Correct |
3 ms |
916 KB |
Output is correct |
24 |
Correct |
1 ms |
596 KB |
Output is correct |
25 |
Correct |
3 ms |
852 KB |
Output is correct |
26 |
Correct |
3 ms |
912 KB |
Output is correct |
27 |
Correct |
2 ms |
852 KB |
Output is correct |
28 |
Correct |
3 ms |
848 KB |
Output is correct |
29 |
Correct |
2 ms |
852 KB |
Output is correct |
30 |
Correct |
16 ms |
22988 KB |
Output is correct |
31 |
Correct |
3 ms |
852 KB |
Output is correct |
32 |
Correct |
17 ms |
23100 KB |
Output is correct |
33 |
Correct |
3 ms |
852 KB |
Output is correct |
34 |
Correct |
3 ms |
852 KB |
Output is correct |
35 |
Correct |
2 ms |
568 KB |
Output is correct |
36 |
Correct |
2 ms |
596 KB |
Output is correct |
37 |
Correct |
2 ms |
596 KB |
Output is correct |
38 |
Correct |
3 ms |
5972 KB |
Output is correct |
39 |
Correct |
3 ms |
5972 KB |
Output is correct |
40 |
Correct |
10 ms |
24916 KB |
Output is correct |
41 |
Correct |
3 ms |
5972 KB |
Output is correct |
42 |
Correct |
10 ms |
24700 KB |
Output is correct |
43 |
Correct |
11 ms |
24788 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
468 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
356 ms |
7556 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
367 ms |
10204 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
363 ms |
10196 KB |
Output is correct |
16 |
Correct |
367 ms |
10272 KB |
Output is correct |
17 |
Correct |
366 ms |
10196 KB |
Output is correct |
18 |
Correct |
366 ms |
10200 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
2 ms |
852 KB |
Output is correct |
4 |
Correct |
1 ms |
852 KB |
Output is correct |
5 |
Correct |
2 ms |
852 KB |
Output is correct |
6 |
Correct |
2 ms |
852 KB |
Output is correct |
7 |
Correct |
2 ms |
852 KB |
Output is correct |
8 |
Correct |
1 ms |
468 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
468 KB |
Output is correct |
11 |
Correct |
2 ms |
852 KB |
Output is correct |
12 |
Correct |
27 ms |
21012 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
28 ms |
21016 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
10 ms |
18952 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
10 ms |
18644 KB |
Output is correct |
19 |
Correct |
1 ms |
596 KB |
Output is correct |
20 |
Correct |
2 ms |
852 KB |
Output is correct |
21 |
Correct |
1 ms |
852 KB |
Output is correct |
22 |
Correct |
1 ms |
468 KB |
Output is correct |
23 |
Correct |
3 ms |
916 KB |
Output is correct |
24 |
Correct |
1 ms |
596 KB |
Output is correct |
25 |
Correct |
3 ms |
852 KB |
Output is correct |
26 |
Correct |
3 ms |
912 KB |
Output is correct |
27 |
Correct |
2 ms |
852 KB |
Output is correct |
28 |
Correct |
3 ms |
848 KB |
Output is correct |
29 |
Correct |
2 ms |
852 KB |
Output is correct |
30 |
Correct |
16 ms |
22988 KB |
Output is correct |
31 |
Correct |
3 ms |
852 KB |
Output is correct |
32 |
Correct |
17 ms |
23100 KB |
Output is correct |
33 |
Correct |
3 ms |
852 KB |
Output is correct |
34 |
Correct |
3 ms |
852 KB |
Output is correct |
35 |
Correct |
2 ms |
568 KB |
Output is correct |
36 |
Correct |
2 ms |
596 KB |
Output is correct |
37 |
Correct |
2 ms |
596 KB |
Output is correct |
38 |
Correct |
3 ms |
5972 KB |
Output is correct |
39 |
Correct |
3 ms |
5972 KB |
Output is correct |
40 |
Correct |
10 ms |
24916 KB |
Output is correct |
41 |
Correct |
3 ms |
5972 KB |
Output is correct |
42 |
Correct |
10 ms |
24700 KB |
Output is correct |
43 |
Correct |
11 ms |
24788 KB |
Output is correct |
44 |
Correct |
19 ms |
1236 KB |
Output is correct |
45 |
Correct |
1 ms |
212 KB |
Output is correct |
46 |
Incorrect |
10 ms |
24444 KB |
Output isn't correct |
47 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
2 ms |
852 KB |
Output is correct |
4 |
Correct |
1 ms |
852 KB |
Output is correct |
5 |
Correct |
2 ms |
852 KB |
Output is correct |
6 |
Correct |
2 ms |
852 KB |
Output is correct |
7 |
Correct |
2 ms |
852 KB |
Output is correct |
8 |
Correct |
1 ms |
468 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
468 KB |
Output is correct |
11 |
Correct |
2 ms |
852 KB |
Output is correct |
12 |
Correct |
27 ms |
21012 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
28 ms |
21016 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
10 ms |
18952 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
10 ms |
18644 KB |
Output is correct |
19 |
Correct |
1 ms |
596 KB |
Output is correct |
20 |
Correct |
2 ms |
852 KB |
Output is correct |
21 |
Correct |
1 ms |
852 KB |
Output is correct |
22 |
Correct |
1 ms |
468 KB |
Output is correct |
23 |
Correct |
3 ms |
916 KB |
Output is correct |
24 |
Correct |
1 ms |
596 KB |
Output is correct |
25 |
Correct |
3 ms |
852 KB |
Output is correct |
26 |
Correct |
3 ms |
912 KB |
Output is correct |
27 |
Correct |
2 ms |
852 KB |
Output is correct |
28 |
Correct |
3 ms |
848 KB |
Output is correct |
29 |
Correct |
2 ms |
852 KB |
Output is correct |
30 |
Correct |
16 ms |
22988 KB |
Output is correct |
31 |
Correct |
3 ms |
852 KB |
Output is correct |
32 |
Correct |
17 ms |
23100 KB |
Output is correct |
33 |
Correct |
3 ms |
852 KB |
Output is correct |
34 |
Correct |
3 ms |
852 KB |
Output is correct |
35 |
Correct |
2 ms |
568 KB |
Output is correct |
36 |
Correct |
2 ms |
596 KB |
Output is correct |
37 |
Correct |
2 ms |
596 KB |
Output is correct |
38 |
Correct |
3 ms |
5972 KB |
Output is correct |
39 |
Correct |
3 ms |
5972 KB |
Output is correct |
40 |
Correct |
10 ms |
24916 KB |
Output is correct |
41 |
Correct |
3 ms |
5972 KB |
Output is correct |
42 |
Correct |
10 ms |
24700 KB |
Output is correct |
43 |
Correct |
11 ms |
24788 KB |
Output is correct |
44 |
Correct |
1 ms |
324 KB |
Output is correct |
45 |
Runtime error |
59 ms |
64076 KB |
Execution killed with signal 11 |
46 |
Halted |
0 ms |
0 KB |
- |