//Challenge: Accepted
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <stack>
#include <queue>
#include <cmath>
#include <assert.h>
#include <unordered_set>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
using namespace std;
//using namespace __gnu_pbds;
void debug() {cout << endl;}
template <class T, class ...U> void debug(T a, U ... b) { cout << a << " "; debug(b...);}
template <class T> void pary(T l, T r) {
while (l != r) {cout << *l << " ";l++;}
cout << endl;
}
#define ll long long
#define ld long double
#define maxn 50005
#define mod 1000000007
#define pii pair<int, int>
#define ff first
#define ss second
#define io ios_base::sync_with_stdio(0);cin.tie(0);
unordered_set<int> ed[maxn];
int ord[maxn], deg[maxn], found[maxn], g[15];
int ans = 0;
int getans(int s, int cur, int ind, int se) {
if (ind >= s) return 0;
int ret = 0;
for (int v = ind;v < s;v++) {
if (((g[v] & se) & (cur | (1<<v))) == (cur | (1<<v))) {
ret = max(ret, getans(s, cur | (1<<v), v + 1, g[v] & se) + 1);
}
}
return ret;
}
void solve(int n) {
vector<int> se;
se.push_back(n);
for (int v:ed[n]) {
if (!found[v]) se.push_back(v);
}
//pary(se.begin(), se.end());
if (se.size() <= ans) return;
for (int i = 0;i < se.size();i++) g[i] = 0;
for (int i = 0;i < se.size();i++) {
for (int j = i;j < se.size();j++) {
if (i == j) g[i] += 1<<i;
else {
int v = ed[se[i]].find(se[j]) == ed[se[i]].end() ? 0 : 1;
//debug(se[i], se[j], v);
g[i] += (1<<j) * v;
g[j] += (1<<i) * v;
}
}
}
//pary(g, g + se.size());
ans = max(ans, getans(se.size(), 0, 0, (1<<se.size()) - 1));
}
int main() {
io
int n, k;
cin >> n >> k;
for (int i = 0;i < n;i++) {
int di;
cin >> di;
deg[i] = di;
for (int j = 0;j < di;j++) {
int x;cin >> x;
ed[i].insert(x);
}
}
queue<int> que;
for (int i = 0;i < n;i++) {
if (deg[i] < k) {
que.push(i); found[i] = 1;
}
}
int ind = 0;
while (que.size()) {
int cur = que.front();que.pop();
ord[ind++] = cur;
for (int v:ed[cur]) {
if (--deg[v] < k && !found[v]) {
que.push(v);found[v] = 1;
}
}
}
for (int i = 0;i < n;i++) found[i] = 0;
for (int i = 0;i < n;i++) solve(ord[i]), found[ord[i]] = 1;
cout << ans << endl;
}
/*
5 3
2 1 2
3 0 2 3
3 0 1 4
2 1 4
2 2 3
*/
Compilation message
politicaldevelopment.cpp: In function 'void solve(int)':
politicaldevelopment.cpp:49:16: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
49 | if (se.size() <= ans) return;
| ~~~~~~~~~~^~~~~~
politicaldevelopment.cpp:50:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
50 | for (int i = 0;i < se.size();i++) g[i] = 0;
| ~~^~~~~~~~~~~
politicaldevelopment.cpp:51:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
51 | for (int i = 0;i < se.size();i++) {
| ~~^~~~~~~~~~~
politicaldevelopment.cpp:52:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
52 | for (int j = i;j < se.size();j++) {
| ~~^~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
3020 KB |
Output is correct |
2 |
Correct |
2 ms |
3020 KB |
Output is correct |
3 |
Correct |
6 ms |
3916 KB |
Output is correct |
4 |
Correct |
6 ms |
4044 KB |
Output is correct |
5 |
Correct |
8 ms |
4044 KB |
Output is correct |
6 |
Correct |
6 ms |
4064 KB |
Output is correct |
7 |
Correct |
6 ms |
4044 KB |
Output is correct |
8 |
Correct |
3 ms |
3020 KB |
Output is correct |
9 |
Correct |
3 ms |
3020 KB |
Output is correct |
10 |
Correct |
4 ms |
3148 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
3020 KB |
Output is correct |
2 |
Correct |
2 ms |
3020 KB |
Output is correct |
3 |
Correct |
6 ms |
3916 KB |
Output is correct |
4 |
Correct |
6 ms |
4044 KB |
Output is correct |
5 |
Correct |
8 ms |
4044 KB |
Output is correct |
6 |
Correct |
6 ms |
4064 KB |
Output is correct |
7 |
Correct |
6 ms |
4044 KB |
Output is correct |
8 |
Correct |
3 ms |
3020 KB |
Output is correct |
9 |
Correct |
3 ms |
3020 KB |
Output is correct |
10 |
Correct |
4 ms |
3148 KB |
Output is correct |
11 |
Correct |
7 ms |
3992 KB |
Output is correct |
12 |
Correct |
6 ms |
4044 KB |
Output is correct |
13 |
Correct |
3 ms |
3020 KB |
Output is correct |
14 |
Correct |
8 ms |
4096 KB |
Output is correct |
15 |
Correct |
3 ms |
3020 KB |
Output is correct |
16 |
Correct |
7 ms |
4044 KB |
Output is correct |
17 |
Correct |
3 ms |
3060 KB |
Output is correct |
18 |
Correct |
6 ms |
4096 KB |
Output is correct |
19 |
Correct |
3 ms |
3068 KB |
Output is correct |
20 |
Correct |
6 ms |
3840 KB |
Output is correct |
21 |
Correct |
5 ms |
3788 KB |
Output is correct |
22 |
Correct |
3 ms |
3148 KB |
Output is correct |
23 |
Correct |
8 ms |
4100 KB |
Output is correct |
24 |
Correct |
3 ms |
3148 KB |
Output is correct |
25 |
Correct |
7 ms |
4052 KB |
Output is correct |
26 |
Correct |
7 ms |
3980 KB |
Output is correct |
27 |
Correct |
6 ms |
3976 KB |
Output is correct |
28 |
Correct |
7 ms |
4088 KB |
Output is correct |
29 |
Correct |
6 ms |
4052 KB |
Output is correct |
30 |
Correct |
9 ms |
4104 KB |
Output is correct |
31 |
Correct |
7 ms |
4100 KB |
Output is correct |
32 |
Correct |
7 ms |
4176 KB |
Output is correct |
33 |
Correct |
7 ms |
4172 KB |
Output is correct |
34 |
Correct |
8 ms |
4180 KB |
Output is correct |
35 |
Correct |
5 ms |
3540 KB |
Output is correct |
36 |
Correct |
6 ms |
3592 KB |
Output is correct |
37 |
Correct |
5 ms |
3592 KB |
Output is correct |
38 |
Correct |
5 ms |
3456 KB |
Output is correct |
39 |
Correct |
4 ms |
3412 KB |
Output is correct |
40 |
Correct |
9 ms |
4388 KB |
Output is correct |
41 |
Correct |
5 ms |
3404 KB |
Output is correct |
42 |
Correct |
9 ms |
4412 KB |
Output is correct |
43 |
Correct |
11 ms |
4300 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
3020 KB |
Output is correct |
2 |
Correct |
2 ms |
3020 KB |
Output is correct |
3 |
Correct |
3 ms |
3064 KB |
Output is correct |
4 |
Correct |
3 ms |
3020 KB |
Output is correct |
5 |
Correct |
3 ms |
3032 KB |
Output is correct |
6 |
Correct |
3 ms |
3032 KB |
Output is correct |
7 |
Correct |
3 ms |
3076 KB |
Output is correct |
8 |
Correct |
3 ms |
3032 KB |
Output is correct |
9 |
Correct |
3 ms |
3032 KB |
Output is correct |
10 |
Correct |
3 ms |
3032 KB |
Output is correct |
11 |
Correct |
198 ms |
26056 KB |
Output is correct |
12 |
Correct |
3 ms |
3032 KB |
Output is correct |
13 |
Correct |
129 ms |
26016 KB |
Output is correct |
14 |
Correct |
3 ms |
3032 KB |
Output is correct |
15 |
Correct |
173 ms |
26216 KB |
Output is correct |
16 |
Correct |
144 ms |
25936 KB |
Output is correct |
17 |
Correct |
164 ms |
25944 KB |
Output is correct |
18 |
Correct |
141 ms |
25948 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
3020 KB |
Output is correct |
2 |
Correct |
2 ms |
3020 KB |
Output is correct |
3 |
Correct |
6 ms |
3916 KB |
Output is correct |
4 |
Correct |
6 ms |
4044 KB |
Output is correct |
5 |
Correct |
8 ms |
4044 KB |
Output is correct |
6 |
Correct |
6 ms |
4064 KB |
Output is correct |
7 |
Correct |
6 ms |
4044 KB |
Output is correct |
8 |
Correct |
3 ms |
3020 KB |
Output is correct |
9 |
Correct |
3 ms |
3020 KB |
Output is correct |
10 |
Correct |
4 ms |
3148 KB |
Output is correct |
11 |
Correct |
7 ms |
3992 KB |
Output is correct |
12 |
Correct |
6 ms |
4044 KB |
Output is correct |
13 |
Correct |
3 ms |
3020 KB |
Output is correct |
14 |
Correct |
8 ms |
4096 KB |
Output is correct |
15 |
Correct |
3 ms |
3020 KB |
Output is correct |
16 |
Correct |
7 ms |
4044 KB |
Output is correct |
17 |
Correct |
3 ms |
3060 KB |
Output is correct |
18 |
Correct |
6 ms |
4096 KB |
Output is correct |
19 |
Correct |
3 ms |
3068 KB |
Output is correct |
20 |
Correct |
6 ms |
3840 KB |
Output is correct |
21 |
Correct |
5 ms |
3788 KB |
Output is correct |
22 |
Correct |
3 ms |
3148 KB |
Output is correct |
23 |
Correct |
8 ms |
4100 KB |
Output is correct |
24 |
Correct |
3 ms |
3148 KB |
Output is correct |
25 |
Correct |
7 ms |
4052 KB |
Output is correct |
26 |
Correct |
7 ms |
3980 KB |
Output is correct |
27 |
Correct |
6 ms |
3976 KB |
Output is correct |
28 |
Correct |
7 ms |
4088 KB |
Output is correct |
29 |
Correct |
6 ms |
4052 KB |
Output is correct |
30 |
Correct |
9 ms |
4104 KB |
Output is correct |
31 |
Correct |
7 ms |
4100 KB |
Output is correct |
32 |
Correct |
7 ms |
4176 KB |
Output is correct |
33 |
Correct |
7 ms |
4172 KB |
Output is correct |
34 |
Correct |
8 ms |
4180 KB |
Output is correct |
35 |
Correct |
5 ms |
3540 KB |
Output is correct |
36 |
Correct |
6 ms |
3592 KB |
Output is correct |
37 |
Correct |
5 ms |
3592 KB |
Output is correct |
38 |
Correct |
5 ms |
3456 KB |
Output is correct |
39 |
Correct |
4 ms |
3412 KB |
Output is correct |
40 |
Correct |
9 ms |
4388 KB |
Output is correct |
41 |
Correct |
5 ms |
3404 KB |
Output is correct |
42 |
Correct |
9 ms |
4412 KB |
Output is correct |
43 |
Correct |
11 ms |
4300 KB |
Output is correct |
44 |
Correct |
13 ms |
5104 KB |
Output is correct |
45 |
Correct |
3 ms |
3028 KB |
Output is correct |
46 |
Correct |
9 ms |
4300 KB |
Output is correct |
47 |
Correct |
16 ms |
5196 KB |
Output is correct |
48 |
Correct |
9 ms |
4352 KB |
Output is correct |
49 |
Correct |
16 ms |
5196 KB |
Output is correct |
50 |
Correct |
18 ms |
5124 KB |
Output is correct |
51 |
Correct |
36 ms |
6932 KB |
Output is correct |
52 |
Correct |
6 ms |
4044 KB |
Output is correct |
53 |
Correct |
26 ms |
7232 KB |
Output is correct |
54 |
Correct |
39 ms |
7328 KB |
Output is correct |
55 |
Correct |
8 ms |
4044 KB |
Output is correct |
56 |
Correct |
6 ms |
4044 KB |
Output is correct |
57 |
Correct |
3 ms |
3148 KB |
Output is correct |
58 |
Correct |
28 ms |
7212 KB |
Output is correct |
59 |
Correct |
8 ms |
4300 KB |
Output is correct |
60 |
Correct |
6 ms |
4044 KB |
Output is correct |
61 |
Correct |
8 ms |
4312 KB |
Output is correct |
62 |
Correct |
9 ms |
4420 KB |
Output is correct |
63 |
Correct |
12 ms |
5080 KB |
Output is correct |
64 |
Correct |
11 ms |
4976 KB |
Output is correct |
65 |
Correct |
10 ms |
4280 KB |
Output is correct |
66 |
Correct |
8 ms |
4428 KB |
Output is correct |
67 |
Correct |
16 ms |
5552 KB |
Output is correct |
68 |
Correct |
11 ms |
4968 KB |
Output is correct |
69 |
Correct |
10 ms |
4224 KB |
Output is correct |
70 |
Correct |
13 ms |
4904 KB |
Output is correct |
71 |
Correct |
19 ms |
5536 KB |
Output is correct |
72 |
Correct |
16 ms |
5548 KB |
Output is correct |
73 |
Correct |
7 ms |
3968 KB |
Output is correct |
74 |
Correct |
13 ms |
5020 KB |
Output is correct |
75 |
Correct |
16 ms |
5484 KB |
Output is correct |
76 |
Correct |
11 ms |
4608 KB |
Output is correct |
77 |
Correct |
21 ms |
5836 KB |
Output is correct |
78 |
Correct |
6 ms |
4044 KB |
Output is correct |
79 |
Correct |
11 ms |
4428 KB |
Output is correct |
80 |
Correct |
11 ms |
4676 KB |
Output is correct |
81 |
Correct |
20 ms |
5768 KB |
Output is correct |
82 |
Correct |
4 ms |
3404 KB |
Output is correct |
83 |
Correct |
11 ms |
4428 KB |
Output is correct |
84 |
Correct |
19 ms |
5324 KB |
Output is correct |
85 |
Correct |
5 ms |
3404 KB |
Output is correct |
86 |
Correct |
14 ms |
5324 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
3020 KB |
Output is correct |
2 |
Correct |
2 ms |
3020 KB |
Output is correct |
3 |
Correct |
6 ms |
3916 KB |
Output is correct |
4 |
Correct |
6 ms |
4044 KB |
Output is correct |
5 |
Correct |
8 ms |
4044 KB |
Output is correct |
6 |
Correct |
6 ms |
4064 KB |
Output is correct |
7 |
Correct |
6 ms |
4044 KB |
Output is correct |
8 |
Correct |
3 ms |
3020 KB |
Output is correct |
9 |
Correct |
3 ms |
3020 KB |
Output is correct |
10 |
Correct |
4 ms |
3148 KB |
Output is correct |
11 |
Correct |
7 ms |
3992 KB |
Output is correct |
12 |
Correct |
6 ms |
4044 KB |
Output is correct |
13 |
Correct |
3 ms |
3020 KB |
Output is correct |
14 |
Correct |
8 ms |
4096 KB |
Output is correct |
15 |
Correct |
3 ms |
3020 KB |
Output is correct |
16 |
Correct |
7 ms |
4044 KB |
Output is correct |
17 |
Correct |
3 ms |
3060 KB |
Output is correct |
18 |
Correct |
6 ms |
4096 KB |
Output is correct |
19 |
Correct |
3 ms |
3068 KB |
Output is correct |
20 |
Correct |
6 ms |
3840 KB |
Output is correct |
21 |
Correct |
5 ms |
3788 KB |
Output is correct |
22 |
Correct |
3 ms |
3148 KB |
Output is correct |
23 |
Correct |
8 ms |
4100 KB |
Output is correct |
24 |
Correct |
3 ms |
3148 KB |
Output is correct |
25 |
Correct |
7 ms |
4052 KB |
Output is correct |
26 |
Correct |
7 ms |
3980 KB |
Output is correct |
27 |
Correct |
6 ms |
3976 KB |
Output is correct |
28 |
Correct |
7 ms |
4088 KB |
Output is correct |
29 |
Correct |
6 ms |
4052 KB |
Output is correct |
30 |
Correct |
9 ms |
4104 KB |
Output is correct |
31 |
Correct |
7 ms |
4100 KB |
Output is correct |
32 |
Correct |
7 ms |
4176 KB |
Output is correct |
33 |
Correct |
7 ms |
4172 KB |
Output is correct |
34 |
Correct |
8 ms |
4180 KB |
Output is correct |
35 |
Correct |
5 ms |
3540 KB |
Output is correct |
36 |
Correct |
6 ms |
3592 KB |
Output is correct |
37 |
Correct |
5 ms |
3592 KB |
Output is correct |
38 |
Correct |
5 ms |
3456 KB |
Output is correct |
39 |
Correct |
4 ms |
3412 KB |
Output is correct |
40 |
Correct |
9 ms |
4388 KB |
Output is correct |
41 |
Correct |
5 ms |
3404 KB |
Output is correct |
42 |
Correct |
9 ms |
4412 KB |
Output is correct |
43 |
Correct |
11 ms |
4300 KB |
Output is correct |
44 |
Correct |
2 ms |
3020 KB |
Output is correct |
45 |
Correct |
130 ms |
20656 KB |
Output is correct |
46 |
Correct |
53 ms |
15264 KB |
Output is correct |
47 |
Correct |
121 ms |
20588 KB |
Output is correct |
48 |
Correct |
128 ms |
20720 KB |
Output is correct |
49 |
Correct |
46 ms |
13784 KB |
Output is correct |
50 |
Correct |
148 ms |
26880 KB |
Output is correct |
51 |
Correct |
134 ms |
20548 KB |
Output is correct |
52 |
Correct |
39 ms |
13464 KB |
Output is correct |
53 |
Correct |
38 ms |
13780 KB |
Output is correct |
54 |
Correct |
10 ms |
3944 KB |
Output is correct |
55 |
Correct |
118 ms |
26760 KB |
Output is correct |
56 |
Correct |
25 ms |
11212 KB |
Output is correct |
57 |
Correct |
39 ms |
13508 KB |
Output is correct |
58 |
Correct |
49 ms |
14916 KB |
Output is correct |
59 |
Correct |
26 ms |
11164 KB |
Output is correct |
60 |
Correct |
26 ms |
11160 KB |
Output is correct |
61 |
Correct |
59 ms |
14916 KB |
Output is correct |
62 |
Correct |
36 ms |
13092 KB |
Output is correct |
63 |
Correct |
80 ms |
15672 KB |
Output is correct |
64 |
Correct |
26 ms |
11212 KB |
Output is correct |
65 |
Correct |
86 ms |
17600 KB |
Output is correct |
66 |
Correct |
37 ms |
13032 KB |
Output is correct |
67 |
Correct |
72 ms |
15696 KB |
Output is correct |
68 |
Correct |
86 ms |
17176 KB |
Output is correct |
69 |
Correct |
98 ms |
17732 KB |
Output is correct |
70 |
Correct |
41 ms |
13048 KB |
Output is correct |
71 |
Correct |
105 ms |
17192 KB |
Output is correct |
72 |
Correct |
62 ms |
15860 KB |
Output is correct |
73 |
Correct |
107 ms |
18756 KB |
Output is correct |
74 |
Correct |
40 ms |
13064 KB |
Output is correct |
75 |
Correct |
39 ms |
9720 KB |
Output is correct |
76 |
Correct |
62 ms |
15876 KB |
Output is correct |
77 |
Correct |
108 ms |
18768 KB |
Output is correct |
78 |
Correct |
49 ms |
10888 KB |
Output is correct |
79 |
Correct |
51 ms |
9668 KB |
Output is correct |
80 |
Correct |
18 ms |
6564 KB |
Output is correct |
81 |
Correct |
50 ms |
10820 KB |
Output is correct |
82 |
Correct |
73 ms |
16752 KB |
Output is correct |
83 |
Correct |
18 ms |
6648 KB |
Output is correct |
84 |
Correct |
71 ms |
16852 KB |
Output is correct |