#include <bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define all(x) x.begin(), x.end()
using namespace std;
template <class X, class Y> bool minimize(X &a, Y b) {
if (a > b) return a = b, true;
return false;
}
template <class X, class Y> bool maximize(X &a, Y b) {
if (a < b) return a = b, true;
return false;
}
const int N = 5e4 + 7;
int n, k;
int deg[N];
bool vis[N];
bool dp[1 << 10];
bool has_edge[11][11];
vector<int> node;
vector<int> adj[N];
signed main() {
cin.tie(0)->sync_with_stdio(0);
cin >> n >> k;
priority_queue<pair<int, int>> heap;
for (int i = 1; i <= n; i ++) {
cin >> deg[i];
heap.emplace(- deg[i], i);
for (int j = 0; j < deg[i]; j ++) {
int u; cin >> u;
u ++;
adj[i].push_back(u);
}
sort(all(adj[i]));
}
auto calc = [&]() {
int m = node.size();
memset(has_edge, false, sizeof has_edge);
for (int i = 0; i < m; i ++) {
for (int j = 0; j < m; j ++) {
has_edge[i][j] = binary_search(all(adj[node[i]]), node[j]);
}
}
int res = 0;
dp[0] = true;
for (int mask = 1; mask < 1 << m; mask ++) {
int f = -1;
dp[mask] = true;
for (int i = 0; i < m; i ++) {
if (~mask >> i & 1) {
continue;
}
if (f == -1) {
f = i;
dp[mask] = dp[mask ^ (1 << i)];
} else {
dp[mask] &= has_edge[f][i];
}
}
if (dp[mask]) {
maximize(res, __builtin_popcount(mask));
}
}
return res;
};
int res = 0;
while (!heap.empty()) {
int u = heap.top().se;
heap.pop();
if (vis[u]) {
continue;
}
vis[u] = true;
node.clear();
for (int v: adj[u]) if (!vis[v]) {
deg[v] --;
heap.emplace(-deg[v], v);
node.push_back(v);
}
maximize(res, calc() + 1);
}
cout << res;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1492 KB |
Output is correct |
2 |
Correct |
1 ms |
1492 KB |
Output is correct |
3 |
Correct |
4 ms |
1620 KB |
Output is correct |
4 |
Correct |
3 ms |
1748 KB |
Output is correct |
5 |
Correct |
3 ms |
1748 KB |
Output is correct |
6 |
Correct |
3 ms |
1748 KB |
Output is correct |
7 |
Correct |
4 ms |
1748 KB |
Output is correct |
8 |
Correct |
2 ms |
1620 KB |
Output is correct |
9 |
Correct |
1 ms |
1492 KB |
Output is correct |
10 |
Correct |
2 ms |
1620 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1492 KB |
Output is correct |
2 |
Correct |
1 ms |
1492 KB |
Output is correct |
3 |
Correct |
4 ms |
1620 KB |
Output is correct |
4 |
Correct |
3 ms |
1748 KB |
Output is correct |
5 |
Correct |
3 ms |
1748 KB |
Output is correct |
6 |
Correct |
3 ms |
1748 KB |
Output is correct |
7 |
Correct |
4 ms |
1748 KB |
Output is correct |
8 |
Correct |
2 ms |
1620 KB |
Output is correct |
9 |
Correct |
1 ms |
1492 KB |
Output is correct |
10 |
Correct |
2 ms |
1620 KB |
Output is correct |
11 |
Correct |
5 ms |
1748 KB |
Output is correct |
12 |
Correct |
4 ms |
1776 KB |
Output is correct |
13 |
Correct |
1 ms |
1508 KB |
Output is correct |
14 |
Correct |
4 ms |
1748 KB |
Output is correct |
15 |
Correct |
2 ms |
1508 KB |
Output is correct |
16 |
Correct |
5 ms |
1876 KB |
Output is correct |
17 |
Correct |
1 ms |
1492 KB |
Output is correct |
18 |
Correct |
4 ms |
1748 KB |
Output is correct |
19 |
Correct |
1 ms |
1620 KB |
Output is correct |
20 |
Correct |
3 ms |
1772 KB |
Output is correct |
21 |
Correct |
3 ms |
1748 KB |
Output is correct |
22 |
Correct |
2 ms |
1620 KB |
Output is correct |
23 |
Correct |
5 ms |
1752 KB |
Output is correct |
24 |
Correct |
2 ms |
1620 KB |
Output is correct |
25 |
Correct |
5 ms |
1752 KB |
Output is correct |
26 |
Correct |
4 ms |
1752 KB |
Output is correct |
27 |
Correct |
3 ms |
1776 KB |
Output is correct |
28 |
Correct |
5 ms |
1752 KB |
Output is correct |
29 |
Correct |
5 ms |
1748 KB |
Output is correct |
30 |
Correct |
5 ms |
1748 KB |
Output is correct |
31 |
Correct |
6 ms |
1776 KB |
Output is correct |
32 |
Correct |
6 ms |
1744 KB |
Output is correct |
33 |
Correct |
5 ms |
1748 KB |
Output is correct |
34 |
Correct |
4 ms |
1744 KB |
Output is correct |
35 |
Correct |
3 ms |
1648 KB |
Output is correct |
36 |
Correct |
3 ms |
1588 KB |
Output is correct |
37 |
Correct |
3 ms |
1620 KB |
Output is correct |
38 |
Correct |
2 ms |
1620 KB |
Output is correct |
39 |
Correct |
2 ms |
1620 KB |
Output is correct |
40 |
Correct |
7 ms |
1876 KB |
Output is correct |
41 |
Correct |
2 ms |
1620 KB |
Output is correct |
42 |
Correct |
6 ms |
1900 KB |
Output is correct |
43 |
Correct |
6 ms |
1876 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
1620 KB |
Output is correct |
2 |
Correct |
1 ms |
1492 KB |
Output is correct |
3 |
Correct |
1 ms |
1492 KB |
Output is correct |
4 |
Correct |
2 ms |
1492 KB |
Output is correct |
5 |
Correct |
2 ms |
1492 KB |
Output is correct |
6 |
Correct |
1 ms |
1492 KB |
Output is correct |
7 |
Correct |
1 ms |
1492 KB |
Output is correct |
8 |
Correct |
1 ms |
1492 KB |
Output is correct |
9 |
Correct |
1 ms |
1492 KB |
Output is correct |
10 |
Correct |
1 ms |
1492 KB |
Output is correct |
11 |
Correct |
166 ms |
10312 KB |
Output is correct |
12 |
Correct |
1 ms |
1492 KB |
Output is correct |
13 |
Correct |
176 ms |
10296 KB |
Output is correct |
14 |
Correct |
1 ms |
1492 KB |
Output is correct |
15 |
Correct |
158 ms |
10396 KB |
Output is correct |
16 |
Correct |
159 ms |
10372 KB |
Output is correct |
17 |
Correct |
175 ms |
10264 KB |
Output is correct |
18 |
Correct |
161 ms |
10360 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1492 KB |
Output is correct |
2 |
Correct |
1 ms |
1492 KB |
Output is correct |
3 |
Correct |
4 ms |
1620 KB |
Output is correct |
4 |
Correct |
3 ms |
1748 KB |
Output is correct |
5 |
Correct |
3 ms |
1748 KB |
Output is correct |
6 |
Correct |
3 ms |
1748 KB |
Output is correct |
7 |
Correct |
4 ms |
1748 KB |
Output is correct |
8 |
Correct |
2 ms |
1620 KB |
Output is correct |
9 |
Correct |
1 ms |
1492 KB |
Output is correct |
10 |
Correct |
2 ms |
1620 KB |
Output is correct |
11 |
Correct |
5 ms |
1748 KB |
Output is correct |
12 |
Correct |
4 ms |
1776 KB |
Output is correct |
13 |
Correct |
1 ms |
1508 KB |
Output is correct |
14 |
Correct |
4 ms |
1748 KB |
Output is correct |
15 |
Correct |
2 ms |
1508 KB |
Output is correct |
16 |
Correct |
5 ms |
1876 KB |
Output is correct |
17 |
Correct |
1 ms |
1492 KB |
Output is correct |
18 |
Correct |
4 ms |
1748 KB |
Output is correct |
19 |
Correct |
1 ms |
1620 KB |
Output is correct |
20 |
Correct |
3 ms |
1772 KB |
Output is correct |
21 |
Correct |
3 ms |
1748 KB |
Output is correct |
22 |
Correct |
2 ms |
1620 KB |
Output is correct |
23 |
Correct |
5 ms |
1752 KB |
Output is correct |
24 |
Correct |
2 ms |
1620 KB |
Output is correct |
25 |
Correct |
5 ms |
1752 KB |
Output is correct |
26 |
Correct |
4 ms |
1752 KB |
Output is correct |
27 |
Correct |
3 ms |
1776 KB |
Output is correct |
28 |
Correct |
5 ms |
1752 KB |
Output is correct |
29 |
Correct |
5 ms |
1748 KB |
Output is correct |
30 |
Correct |
5 ms |
1748 KB |
Output is correct |
31 |
Correct |
6 ms |
1776 KB |
Output is correct |
32 |
Correct |
6 ms |
1744 KB |
Output is correct |
33 |
Correct |
5 ms |
1748 KB |
Output is correct |
34 |
Correct |
4 ms |
1744 KB |
Output is correct |
35 |
Correct |
3 ms |
1648 KB |
Output is correct |
36 |
Correct |
3 ms |
1588 KB |
Output is correct |
37 |
Correct |
3 ms |
1620 KB |
Output is correct |
38 |
Correct |
2 ms |
1620 KB |
Output is correct |
39 |
Correct |
2 ms |
1620 KB |
Output is correct |
40 |
Correct |
7 ms |
1876 KB |
Output is correct |
41 |
Correct |
2 ms |
1620 KB |
Output is correct |
42 |
Correct |
6 ms |
1900 KB |
Output is correct |
43 |
Correct |
6 ms |
1876 KB |
Output is correct |
44 |
Correct |
15 ms |
2008 KB |
Output is correct |
45 |
Correct |
1 ms |
1492 KB |
Output is correct |
46 |
Correct |
7 ms |
1876 KB |
Output is correct |
47 |
Correct |
13 ms |
2284 KB |
Output is correct |
48 |
Correct |
7 ms |
1876 KB |
Output is correct |
49 |
Correct |
16 ms |
2260 KB |
Output is correct |
50 |
Correct |
14 ms |
2260 KB |
Output is correct |
51 |
Correct |
42 ms |
2920 KB |
Output is correct |
52 |
Correct |
3 ms |
1776 KB |
Output is correct |
53 |
Correct |
60 ms |
3144 KB |
Output is correct |
54 |
Correct |
72 ms |
3080 KB |
Output is correct |
55 |
Correct |
4 ms |
1780 KB |
Output is correct |
56 |
Correct |
4 ms |
1748 KB |
Output is correct |
57 |
Correct |
2 ms |
1620 KB |
Output is correct |
58 |
Correct |
66 ms |
3208 KB |
Output is correct |
59 |
Correct |
6 ms |
1748 KB |
Output is correct |
60 |
Correct |
6 ms |
1748 KB |
Output is correct |
61 |
Correct |
6 ms |
1748 KB |
Output is correct |
62 |
Correct |
5 ms |
1748 KB |
Output is correct |
63 |
Correct |
16 ms |
2012 KB |
Output is correct |
64 |
Correct |
10 ms |
1980 KB |
Output is correct |
65 |
Correct |
6 ms |
1880 KB |
Output is correct |
66 |
Correct |
6 ms |
1820 KB |
Output is correct |
67 |
Correct |
19 ms |
2412 KB |
Output is correct |
68 |
Correct |
13 ms |
1876 KB |
Output is correct |
69 |
Correct |
7 ms |
1880 KB |
Output is correct |
70 |
Correct |
12 ms |
2152 KB |
Output is correct |
71 |
Correct |
20 ms |
2292 KB |
Output is correct |
72 |
Correct |
16 ms |
2384 KB |
Output is correct |
73 |
Correct |
5 ms |
1776 KB |
Output is correct |
74 |
Correct |
12 ms |
2136 KB |
Output is correct |
75 |
Correct |
16 ms |
2336 KB |
Output is correct |
76 |
Correct |
8 ms |
2028 KB |
Output is correct |
77 |
Correct |
23 ms |
2544 KB |
Output is correct |
78 |
Correct |
3 ms |
1776 KB |
Output is correct |
79 |
Correct |
13 ms |
2028 KB |
Output is correct |
80 |
Correct |
8 ms |
2028 KB |
Output is correct |
81 |
Correct |
27 ms |
2516 KB |
Output is correct |
82 |
Correct |
3 ms |
1520 KB |
Output is correct |
83 |
Correct |
13 ms |
2028 KB |
Output is correct |
84 |
Correct |
15 ms |
2416 KB |
Output is correct |
85 |
Correct |
2 ms |
1620 KB |
Output is correct |
86 |
Correct |
18 ms |
2420 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1492 KB |
Output is correct |
2 |
Correct |
1 ms |
1492 KB |
Output is correct |
3 |
Correct |
4 ms |
1620 KB |
Output is correct |
4 |
Correct |
3 ms |
1748 KB |
Output is correct |
5 |
Correct |
3 ms |
1748 KB |
Output is correct |
6 |
Correct |
3 ms |
1748 KB |
Output is correct |
7 |
Correct |
4 ms |
1748 KB |
Output is correct |
8 |
Correct |
2 ms |
1620 KB |
Output is correct |
9 |
Correct |
1 ms |
1492 KB |
Output is correct |
10 |
Correct |
2 ms |
1620 KB |
Output is correct |
11 |
Correct |
5 ms |
1748 KB |
Output is correct |
12 |
Correct |
4 ms |
1776 KB |
Output is correct |
13 |
Correct |
1 ms |
1508 KB |
Output is correct |
14 |
Correct |
4 ms |
1748 KB |
Output is correct |
15 |
Correct |
2 ms |
1508 KB |
Output is correct |
16 |
Correct |
5 ms |
1876 KB |
Output is correct |
17 |
Correct |
1 ms |
1492 KB |
Output is correct |
18 |
Correct |
4 ms |
1748 KB |
Output is correct |
19 |
Correct |
1 ms |
1620 KB |
Output is correct |
20 |
Correct |
3 ms |
1772 KB |
Output is correct |
21 |
Correct |
3 ms |
1748 KB |
Output is correct |
22 |
Correct |
2 ms |
1620 KB |
Output is correct |
23 |
Correct |
5 ms |
1752 KB |
Output is correct |
24 |
Correct |
2 ms |
1620 KB |
Output is correct |
25 |
Correct |
5 ms |
1752 KB |
Output is correct |
26 |
Correct |
4 ms |
1752 KB |
Output is correct |
27 |
Correct |
3 ms |
1776 KB |
Output is correct |
28 |
Correct |
5 ms |
1752 KB |
Output is correct |
29 |
Correct |
5 ms |
1748 KB |
Output is correct |
30 |
Correct |
5 ms |
1748 KB |
Output is correct |
31 |
Correct |
6 ms |
1776 KB |
Output is correct |
32 |
Correct |
6 ms |
1744 KB |
Output is correct |
33 |
Correct |
5 ms |
1748 KB |
Output is correct |
34 |
Correct |
4 ms |
1744 KB |
Output is correct |
35 |
Correct |
3 ms |
1648 KB |
Output is correct |
36 |
Correct |
3 ms |
1588 KB |
Output is correct |
37 |
Correct |
3 ms |
1620 KB |
Output is correct |
38 |
Correct |
2 ms |
1620 KB |
Output is correct |
39 |
Correct |
2 ms |
1620 KB |
Output is correct |
40 |
Correct |
7 ms |
1876 KB |
Output is correct |
41 |
Correct |
2 ms |
1620 KB |
Output is correct |
42 |
Correct |
6 ms |
1900 KB |
Output is correct |
43 |
Correct |
6 ms |
1876 KB |
Output is correct |
44 |
Correct |
1 ms |
1492 KB |
Output is correct |
45 |
Correct |
96 ms |
7892 KB |
Output is correct |
46 |
Correct |
58 ms |
4792 KB |
Output is correct |
47 |
Correct |
98 ms |
7896 KB |
Output is correct |
48 |
Correct |
104 ms |
7880 KB |
Output is correct |
49 |
Correct |
32 ms |
4512 KB |
Output is correct |
50 |
Correct |
102 ms |
8536 KB |
Output is correct |
51 |
Correct |
97 ms |
7872 KB |
Output is correct |
52 |
Correct |
32 ms |
4572 KB |
Output is correct |
53 |
Correct |
29 ms |
4456 KB |
Output is correct |
54 |
Correct |
9 ms |
2292 KB |
Output is correct |
55 |
Correct |
106 ms |
8764 KB |
Output is correct |
56 |
Correct |
19 ms |
4044 KB |
Output is correct |
57 |
Correct |
32 ms |
4536 KB |
Output is correct |
58 |
Correct |
53 ms |
4620 KB |
Output is correct |
59 |
Correct |
24 ms |
4044 KB |
Output is correct |
60 |
Correct |
20 ms |
4044 KB |
Output is correct |
61 |
Correct |
52 ms |
4548 KB |
Output is correct |
62 |
Correct |
29 ms |
4292 KB |
Output is correct |
63 |
Correct |
55 ms |
5576 KB |
Output is correct |
64 |
Correct |
21 ms |
4044 KB |
Output is correct |
65 |
Correct |
77 ms |
6088 KB |
Output is correct |
66 |
Correct |
30 ms |
4324 KB |
Output is correct |
67 |
Correct |
64 ms |
5612 KB |
Output is correct |
68 |
Correct |
72 ms |
5960 KB |
Output is correct |
69 |
Correct |
73 ms |
6044 KB |
Output is correct |
70 |
Correct |
31 ms |
4340 KB |
Output is correct |
71 |
Correct |
74 ms |
5928 KB |
Output is correct |
72 |
Correct |
52 ms |
5460 KB |
Output is correct |
73 |
Correct |
81 ms |
6472 KB |
Output is correct |
74 |
Correct |
31 ms |
4352 KB |
Output is correct |
75 |
Correct |
32 ms |
3616 KB |
Output is correct |
76 |
Correct |
57 ms |
5660 KB |
Output is correct |
77 |
Correct |
83 ms |
6288 KB |
Output is correct |
78 |
Correct |
37 ms |
3920 KB |
Output is correct |
79 |
Correct |
30 ms |
3528 KB |
Output is correct |
80 |
Correct |
15 ms |
2572 KB |
Output is correct |
81 |
Correct |
49 ms |
3948 KB |
Output is correct |
82 |
Correct |
56 ms |
5516 KB |
Output is correct |
83 |
Correct |
18 ms |
2548 KB |
Output is correct |
84 |
Correct |
74 ms |
5444 KB |
Output is correct |