#include <bits/stdc++.h>
#define ll long long
#define all(aaa) aaa.begin(), aaa.end()
using namespace std;
const int N = 5e4 + 5, K = 10;
vector<int> g[N], cand[N], anime[N];
int deg[N], dp[N][1 << K], sz[1 << K];
bool used[N], killed[N], on[N];
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(NULL);
int n, k;
cin >> n >> k;
for (int i = 0; i < n; i++) {
cin >> deg[i];
for (int j = 0; j < deg[i]; j++) {
int x;
cin >> x;
g[i].push_back(x);
}
}
queue<int> q;
for (int i = 0; i < n; i++) {
if (deg[i] < k) {
used[i] = 1;
q.push(i);
}
}
while (!q.empty()) {
int node = q.front();
q.pop();
killed[node] = 1;
for (int to : g[node]) {
if (!used[to]) {
deg[to]--;
if (deg[to] < k) {
used[to] = 1;
q.push(to);
}
}
}
for (int to : g[node]) {
if (!killed[to]) {
anime[to].push_back(node);
cand[node].push_back(to);
}
}
sort(all(cand[node]));
// cout << node << " : ";
// for (int x : cand[node])
// cout << x << " ";
// cout << "\n";
}
for (int i = 0; i < n; i++) {
for (int to : g[i]) {
on[to] = 1;
}
on[i] = 1;
for (int to : anime[i]) {
int m = 0, x;
for (int j = 0; j < cand[to].size(); j++) {
if (on[cand[to][j]]) {
m |= 1 << j;
}
if (cand[to][j] == i)
x = j;
}
// cout << (1 << x) << " " << m << "\n";
dp[to][1 << x] = m;
}
for (int to : g[i]) {
on[to] = 0;
}
on[i] = 0;
}
for (int i = 0; i < (1 << K); i++)
sz[i] = __builtin_popcount(i);
int ans = 1;
for (int i = 0; i < n; i++) {
int len = cand[i].size();
dp[i][0] = (1 << len) - 1;
for (int j = 1; j < (1 << len); j++) {
dp[i][j] = (dp[i][j & -j] & dp[i][j ^ (j & -j)]);
if (j == dp[i][j])
ans = max(ans, sz[j] + 1);
}
}
cout << ans;
return 0;
}
Compilation message
politicaldevelopment.cpp: In function 'int main()':
politicaldevelopment.cpp:78:25: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int j = 0; j < cand[to].size(); j++) {
~~^~~~~~~~~~~~~~~~~
politicaldevelopment.cpp:88:16: warning: 'x' may be used uninitialized in this function [-Wmaybe-uninitialized]
dp[to][1 << x] = m;
~~^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
3832 KB |
Output is correct |
2 |
Correct |
5 ms |
3960 KB |
Output is correct |
3 |
Correct |
26 ms |
24440 KB |
Output is correct |
4 |
Correct |
25 ms |
24284 KB |
Output is correct |
5 |
Correct |
25 ms |
24312 KB |
Output is correct |
6 |
Correct |
24 ms |
24412 KB |
Output is correct |
7 |
Correct |
24 ms |
24440 KB |
Output is correct |
8 |
Correct |
21 ms |
23932 KB |
Output is correct |
9 |
Correct |
5 ms |
3960 KB |
Output is correct |
10 |
Correct |
21 ms |
23928 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
3832 KB |
Output is correct |
2 |
Correct |
5 ms |
3960 KB |
Output is correct |
3 |
Correct |
26 ms |
24440 KB |
Output is correct |
4 |
Correct |
25 ms |
24284 KB |
Output is correct |
5 |
Correct |
25 ms |
24312 KB |
Output is correct |
6 |
Correct |
24 ms |
24412 KB |
Output is correct |
7 |
Correct |
24 ms |
24440 KB |
Output is correct |
8 |
Correct |
21 ms |
23932 KB |
Output is correct |
9 |
Correct |
5 ms |
3960 KB |
Output is correct |
10 |
Correct |
21 ms |
23928 KB |
Output is correct |
11 |
Correct |
23 ms |
24312 KB |
Output is correct |
12 |
Correct |
24 ms |
24392 KB |
Output is correct |
13 |
Correct |
5 ms |
3932 KB |
Output is correct |
14 |
Correct |
23 ms |
24312 KB |
Output is correct |
15 |
Correct |
5 ms |
3960 KB |
Output is correct |
16 |
Correct |
24 ms |
24440 KB |
Output is correct |
17 |
Correct |
5 ms |
3960 KB |
Output is correct |
18 |
Correct |
28 ms |
24440 KB |
Output is correct |
19 |
Correct |
22 ms |
23928 KB |
Output is correct |
20 |
Correct |
22 ms |
24312 KB |
Output is correct |
21 |
Correct |
23 ms |
24312 KB |
Output is correct |
22 |
Correct |
21 ms |
24056 KB |
Output is correct |
23 |
Correct |
26 ms |
24444 KB |
Output is correct |
24 |
Correct |
21 ms |
23928 KB |
Output is correct |
25 |
Correct |
25 ms |
24440 KB |
Output is correct |
26 |
Correct |
25 ms |
24312 KB |
Output is correct |
27 |
Correct |
32 ms |
24440 KB |
Output is correct |
28 |
Correct |
25 ms |
24440 KB |
Output is correct |
29 |
Correct |
24 ms |
24444 KB |
Output is correct |
30 |
Correct |
25 ms |
24440 KB |
Output is correct |
31 |
Correct |
27 ms |
24440 KB |
Output is correct |
32 |
Correct |
27 ms |
24440 KB |
Output is correct |
33 |
Correct |
27 ms |
24568 KB |
Output is correct |
34 |
Correct |
28 ms |
24440 KB |
Output is correct |
35 |
Correct |
33 ms |
14328 KB |
Output is correct |
36 |
Correct |
17 ms |
14200 KB |
Output is correct |
37 |
Correct |
16 ms |
14200 KB |
Output is correct |
38 |
Correct |
10 ms |
8952 KB |
Output is correct |
39 |
Correct |
11 ms |
8952 KB |
Output is correct |
40 |
Correct |
29 ms |
24568 KB |
Output is correct |
41 |
Correct |
10 ms |
8952 KB |
Output is correct |
42 |
Correct |
29 ms |
24444 KB |
Output is correct |
43 |
Correct |
28 ms |
24588 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
21 ms |
24028 KB |
Output is correct |
2 |
Correct |
6 ms |
3960 KB |
Output is correct |
3 |
Correct |
5 ms |
3960 KB |
Output is correct |
4 |
Correct |
5 ms |
3932 KB |
Output is correct |
5 |
Correct |
6 ms |
3960 KB |
Output is correct |
6 |
Correct |
5 ms |
3960 KB |
Output is correct |
7 |
Correct |
5 ms |
3960 KB |
Output is correct |
8 |
Correct |
5 ms |
3960 KB |
Output is correct |
9 |
Correct |
5 ms |
3960 KB |
Output is correct |
10 |
Correct |
5 ms |
3960 KB |
Output is correct |
11 |
Correct |
351 ms |
215268 KB |
Output is correct |
12 |
Correct |
6 ms |
3960 KB |
Output is correct |
13 |
Correct |
339 ms |
215160 KB |
Output is correct |
14 |
Correct |
5 ms |
3960 KB |
Output is correct |
15 |
Correct |
350 ms |
215236 KB |
Output is correct |
16 |
Correct |
340 ms |
215160 KB |
Output is correct |
17 |
Correct |
346 ms |
215200 KB |
Output is correct |
18 |
Correct |
336 ms |
215112 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
3832 KB |
Output is correct |
2 |
Correct |
5 ms |
3960 KB |
Output is correct |
3 |
Correct |
26 ms |
24440 KB |
Output is correct |
4 |
Correct |
25 ms |
24284 KB |
Output is correct |
5 |
Correct |
25 ms |
24312 KB |
Output is correct |
6 |
Correct |
24 ms |
24412 KB |
Output is correct |
7 |
Correct |
24 ms |
24440 KB |
Output is correct |
8 |
Correct |
21 ms |
23932 KB |
Output is correct |
9 |
Correct |
5 ms |
3960 KB |
Output is correct |
10 |
Correct |
21 ms |
23928 KB |
Output is correct |
11 |
Correct |
23 ms |
24312 KB |
Output is correct |
12 |
Correct |
24 ms |
24392 KB |
Output is correct |
13 |
Correct |
5 ms |
3932 KB |
Output is correct |
14 |
Correct |
23 ms |
24312 KB |
Output is correct |
15 |
Correct |
5 ms |
3960 KB |
Output is correct |
16 |
Correct |
24 ms |
24440 KB |
Output is correct |
17 |
Correct |
5 ms |
3960 KB |
Output is correct |
18 |
Correct |
28 ms |
24440 KB |
Output is correct |
19 |
Correct |
22 ms |
23928 KB |
Output is correct |
20 |
Correct |
22 ms |
24312 KB |
Output is correct |
21 |
Correct |
23 ms |
24312 KB |
Output is correct |
22 |
Correct |
21 ms |
24056 KB |
Output is correct |
23 |
Correct |
26 ms |
24444 KB |
Output is correct |
24 |
Correct |
21 ms |
23928 KB |
Output is correct |
25 |
Correct |
25 ms |
24440 KB |
Output is correct |
26 |
Correct |
25 ms |
24312 KB |
Output is correct |
27 |
Correct |
32 ms |
24440 KB |
Output is correct |
28 |
Correct |
25 ms |
24440 KB |
Output is correct |
29 |
Correct |
24 ms |
24444 KB |
Output is correct |
30 |
Correct |
25 ms |
24440 KB |
Output is correct |
31 |
Correct |
27 ms |
24440 KB |
Output is correct |
32 |
Correct |
27 ms |
24440 KB |
Output is correct |
33 |
Correct |
27 ms |
24568 KB |
Output is correct |
34 |
Correct |
28 ms |
24440 KB |
Output is correct |
35 |
Correct |
33 ms |
14328 KB |
Output is correct |
36 |
Correct |
17 ms |
14200 KB |
Output is correct |
37 |
Correct |
16 ms |
14200 KB |
Output is correct |
38 |
Correct |
10 ms |
8952 KB |
Output is correct |
39 |
Correct |
11 ms |
8952 KB |
Output is correct |
40 |
Correct |
29 ms |
24568 KB |
Output is correct |
41 |
Correct |
10 ms |
8952 KB |
Output is correct |
42 |
Correct |
29 ms |
24444 KB |
Output is correct |
43 |
Correct |
28 ms |
24588 KB |
Output is correct |
44 |
Correct |
33 ms |
24824 KB |
Output is correct |
45 |
Correct |
5 ms |
3936 KB |
Output is correct |
46 |
Correct |
32 ms |
24540 KB |
Output is correct |
47 |
Correct |
32 ms |
24748 KB |
Output is correct |
48 |
Correct |
27 ms |
24568 KB |
Output is correct |
49 |
Correct |
35 ms |
24952 KB |
Output is correct |
50 |
Correct |
32 ms |
24824 KB |
Output is correct |
51 |
Correct |
44 ms |
25468 KB |
Output is correct |
52 |
Correct |
23 ms |
24312 KB |
Output is correct |
53 |
Correct |
44 ms |
25592 KB |
Output is correct |
54 |
Correct |
51 ms |
25820 KB |
Output is correct |
55 |
Correct |
24 ms |
24440 KB |
Output is correct |
56 |
Correct |
23 ms |
24312 KB |
Output is correct |
57 |
Correct |
21 ms |
23928 KB |
Output is correct |
58 |
Correct |
46 ms |
25592 KB |
Output is correct |
59 |
Correct |
27 ms |
24440 KB |
Output is correct |
60 |
Correct |
23 ms |
24440 KB |
Output is correct |
61 |
Correct |
27 ms |
24440 KB |
Output is correct |
62 |
Correct |
26 ms |
24440 KB |
Output is correct |
63 |
Correct |
31 ms |
24696 KB |
Output is correct |
64 |
Correct |
54 ms |
24696 KB |
Output is correct |
65 |
Correct |
26 ms |
24440 KB |
Output is correct |
66 |
Correct |
28 ms |
24440 KB |
Output is correct |
67 |
Correct |
37 ms |
24952 KB |
Output is correct |
68 |
Correct |
31 ms |
24696 KB |
Output is correct |
69 |
Correct |
27 ms |
24440 KB |
Output is correct |
70 |
Correct |
31 ms |
24696 KB |
Output is correct |
71 |
Correct |
35 ms |
24952 KB |
Output is correct |
72 |
Correct |
35 ms |
24952 KB |
Output is correct |
73 |
Correct |
24 ms |
24440 KB |
Output is correct |
74 |
Correct |
32 ms |
24696 KB |
Output is correct |
75 |
Correct |
35 ms |
24880 KB |
Output is correct |
76 |
Correct |
28 ms |
24568 KB |
Output is correct |
77 |
Correct |
48 ms |
25052 KB |
Output is correct |
78 |
Correct |
26 ms |
24440 KB |
Output is correct |
79 |
Correct |
24 ms |
14500 KB |
Output is correct |
80 |
Correct |
46 ms |
24644 KB |
Output is correct |
81 |
Correct |
38 ms |
25080 KB |
Output is correct |
82 |
Correct |
10 ms |
8952 KB |
Output is correct |
83 |
Correct |
21 ms |
14456 KB |
Output is correct |
84 |
Correct |
33 ms |
24952 KB |
Output is correct |
85 |
Correct |
10 ms |
8952 KB |
Output is correct |
86 |
Correct |
35 ms |
24952 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
3832 KB |
Output is correct |
2 |
Correct |
5 ms |
3960 KB |
Output is correct |
3 |
Correct |
26 ms |
24440 KB |
Output is correct |
4 |
Correct |
25 ms |
24284 KB |
Output is correct |
5 |
Correct |
25 ms |
24312 KB |
Output is correct |
6 |
Correct |
24 ms |
24412 KB |
Output is correct |
7 |
Correct |
24 ms |
24440 KB |
Output is correct |
8 |
Correct |
21 ms |
23932 KB |
Output is correct |
9 |
Correct |
5 ms |
3960 KB |
Output is correct |
10 |
Correct |
21 ms |
23928 KB |
Output is correct |
11 |
Correct |
23 ms |
24312 KB |
Output is correct |
12 |
Correct |
24 ms |
24392 KB |
Output is correct |
13 |
Correct |
5 ms |
3932 KB |
Output is correct |
14 |
Correct |
23 ms |
24312 KB |
Output is correct |
15 |
Correct |
5 ms |
3960 KB |
Output is correct |
16 |
Correct |
24 ms |
24440 KB |
Output is correct |
17 |
Correct |
5 ms |
3960 KB |
Output is correct |
18 |
Correct |
28 ms |
24440 KB |
Output is correct |
19 |
Correct |
22 ms |
23928 KB |
Output is correct |
20 |
Correct |
22 ms |
24312 KB |
Output is correct |
21 |
Correct |
23 ms |
24312 KB |
Output is correct |
22 |
Correct |
21 ms |
24056 KB |
Output is correct |
23 |
Correct |
26 ms |
24444 KB |
Output is correct |
24 |
Correct |
21 ms |
23928 KB |
Output is correct |
25 |
Correct |
25 ms |
24440 KB |
Output is correct |
26 |
Correct |
25 ms |
24312 KB |
Output is correct |
27 |
Correct |
32 ms |
24440 KB |
Output is correct |
28 |
Correct |
25 ms |
24440 KB |
Output is correct |
29 |
Correct |
24 ms |
24444 KB |
Output is correct |
30 |
Correct |
25 ms |
24440 KB |
Output is correct |
31 |
Correct |
27 ms |
24440 KB |
Output is correct |
32 |
Correct |
27 ms |
24440 KB |
Output is correct |
33 |
Correct |
27 ms |
24568 KB |
Output is correct |
34 |
Correct |
28 ms |
24440 KB |
Output is correct |
35 |
Correct |
33 ms |
14328 KB |
Output is correct |
36 |
Correct |
17 ms |
14200 KB |
Output is correct |
37 |
Correct |
16 ms |
14200 KB |
Output is correct |
38 |
Correct |
10 ms |
8952 KB |
Output is correct |
39 |
Correct |
11 ms |
8952 KB |
Output is correct |
40 |
Correct |
29 ms |
24568 KB |
Output is correct |
41 |
Correct |
10 ms |
8952 KB |
Output is correct |
42 |
Correct |
29 ms |
24444 KB |
Output is correct |
43 |
Correct |
28 ms |
24588 KB |
Output is correct |
44 |
Correct |
5 ms |
3964 KB |
Output is correct |
45 |
Correct |
283 ms |
211808 KB |
Output is correct |
46 |
Correct |
342 ms |
209656 KB |
Output is correct |
47 |
Correct |
291 ms |
211960 KB |
Output is correct |
48 |
Correct |
289 ms |
211832 KB |
Output is correct |
49 |
Correct |
180 ms |
208844 KB |
Output is correct |
50 |
Correct |
238 ms |
211784 KB |
Output is correct |
51 |
Correct |
294 ms |
211760 KB |
Output is correct |
52 |
Correct |
191 ms |
208888 KB |
Output is correct |
53 |
Correct |
179 ms |
208756 KB |
Output is correct |
54 |
Correct |
164 ms |
205048 KB |
Output is correct |
55 |
Correct |
236 ms |
211696 KB |
Output is correct |
56 |
Correct |
194 ms |
208120 KB |
Output is correct |
57 |
Correct |
190 ms |
209056 KB |
Output is correct |
58 |
Correct |
226 ms |
209528 KB |
Output is correct |
59 |
Correct |
182 ms |
208212 KB |
Output is correct |
60 |
Correct |
183 ms |
208164 KB |
Output is correct |
61 |
Correct |
233 ms |
209508 KB |
Output is correct |
62 |
Correct |
229 ms |
208888 KB |
Output is correct |
63 |
Correct |
259 ms |
209912 KB |
Output is correct |
64 |
Correct |
189 ms |
208160 KB |
Output is correct |
65 |
Correct |
261 ms |
210672 KB |
Output is correct |
66 |
Correct |
203 ms |
208888 KB |
Output is correct |
67 |
Correct |
241 ms |
210100 KB |
Output is correct |
68 |
Correct |
259 ms |
210552 KB |
Output is correct |
69 |
Correct |
289 ms |
210680 KB |
Output is correct |
70 |
Correct |
204 ms |
208892 KB |
Output is correct |
71 |
Correct |
258 ms |
210572 KB |
Output is correct |
72 |
Correct |
227 ms |
210040 KB |
Output is correct |
73 |
Correct |
273 ms |
211064 KB |
Output is correct |
74 |
Correct |
207 ms |
209072 KB |
Output is correct |
75 |
Correct |
122 ms |
107036 KB |
Output is correct |
76 |
Correct |
228 ms |
210040 KB |
Output is correct |
77 |
Correct |
272 ms |
211064 KB |
Output is correct |
78 |
Correct |
134 ms |
107512 KB |
Output is correct |
79 |
Correct |
129 ms |
107000 KB |
Output is correct |
80 |
Correct |
57 ms |
55288 KB |
Output is correct |
81 |
Correct |
133 ms |
107384 KB |
Output is correct |
82 |
Correct |
242 ms |
209916 KB |
Output is correct |
83 |
Correct |
58 ms |
55288 KB |
Output is correct |
84 |
Correct |
267 ms |
209884 KB |
Output is correct |