/* Author : Mychecksdead */
#include<bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef long long int ll;
typedef long double ld;
#define MOD (1000000000+7)
#define MOD1 (998244353)
#define PI 3.1415926535
#define pb push_back
#define setp() cout << setprecision(15)
#define all(x) x.begin(), x.end()
#define oset tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update>
#define debug(x) cerr << #x << " is " << x << '\n';
const int N = 1e6+100, M = 1e5+10, F = 2147483646, K = 20, MO = 99000007;
int n, k;
vector<int> g[N], path, r[N];
vector<bool> vis(N);
vector<bitset<50005>> is;
ll e[N];
void dfs(int v, int p){
vis[v] = 1;
path.pb(v);
for(int u: g[v]){
if(u != p){
if(vis[u]){
if(path[path.size() - 3] == u){
cout << 3;
exit(0);
}
}else{
dfs(u, v);
}
}
}
path.pop_back();
}
int mod(ll a){
return ((a%MO)+MO)%MO;
}
vector<vector<int>> v;
void solve(){
cin >> n >> k;
is.resize(n+1);
for(int i = 0; i < n; ++i){
int d; cin >> d;
for(int j = 0; j < d; ++j){
int x; cin >> x; g[i].pb(x); is[i][x] = 1;
if(x > i) r[i].pb(x);
}
}
if(k <= 2){
for(int i = 0; i < n; ++i){
if(g[i].size()){
cout << 2;
return;
}
}
cout << 1;
return;
}
if(k <= 3){
for(int i = 0; i < n; ++i) if(!vis[i]) dfs(i, i);
for(int i = 0; i < n; ++i){
if(g[i].size()){
cout << 2;
return;
}
}
cout << 1;
return;
}
e[0] = 1;
for(int i = 1; i < N; ++i) e[i] = (e[i - 1] * 5) % MO;
bool o = 0;
for(int i = 0; i < n; ++i) if(g[i].size() > 0) o = 1;
if(!o){
cout << 1;
return;
}
bitset<50005> bb;
for(int i = 0; i < n; ++i){
for(int u: r[i]){
int x = i, y = u;
if(r[x].size() > r[y].size()) swap(x, y);
for(int p: r[x]){
if(p != y && is[p][y]){
v.pb(vector<int> {x, y, p});
}
}
}
}
if(v.size() == 0){
cout << 2;
return;
}
for(int j = 4; j <= k; ++j){
bitset<50005> out, in;
vector<vector<int>> t;
bitset<N*100> m;
for(auto &u: v){
ll h = 0;
for(int x: u) in[x] = 1, h += e[x];
h = mod(h);
vector<int> extend;
for(int x: u){
for(int e: g[x]){
if(!out[e] && !in[e]){
out[e] = 1;
extend.pb(e);
}
}
}
for(int x: extend){
out[x] = 0;
bool ok = 1;
for(int p: u){
if(!is[p][x]){
ok = 0;
break;
}
}
if(ok){
h = mod(h + e[x]);
if(!m[h]){
m[h] = 1;
u.pb(x);
t.pb(u);
u.pop_back();
}
h = mod(h - e[x]);
}
}
for(int x: u) in[x] = 0;
}
if(t.size() == 0){
cout << j - 1;
return;
}
v = t;
}
cout << k;
}
int main(){
cin.tie(0); ios::sync_with_stdio(0);
int T = 1, aa;
// cin >> T;aa=T;
while(T--){
// cout << "Case #" << aa-T << ": ";
solve();
cout << '\n';
}
return 0;
}
Compilation message
politicaldevelopment.cpp: In function 'int main()':
politicaldevelopment.cpp:162:16: warning: unused variable 'aa' [-Wunused-variable]
162 | int T = 1, aa;
| ^~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
29 ms |
59604 KB |
Output is correct |
2 |
Correct |
32 ms |
59640 KB |
Output is correct |
3 |
Correct |
43 ms |
90540 KB |
Output is correct |
4 |
Correct |
47 ms |
90532 KB |
Output is correct |
5 |
Correct |
43 ms |
90444 KB |
Output is correct |
6 |
Correct |
44 ms |
90444 KB |
Output is correct |
7 |
Correct |
45 ms |
90504 KB |
Output is correct |
8 |
Correct |
43 ms |
90236 KB |
Output is correct |
9 |
Correct |
29 ms |
59604 KB |
Output is correct |
10 |
Correct |
41 ms |
90152 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
29 ms |
59604 KB |
Output is correct |
2 |
Correct |
32 ms |
59640 KB |
Output is correct |
3 |
Correct |
43 ms |
90540 KB |
Output is correct |
4 |
Correct |
47 ms |
90532 KB |
Output is correct |
5 |
Correct |
43 ms |
90444 KB |
Output is correct |
6 |
Correct |
44 ms |
90444 KB |
Output is correct |
7 |
Correct |
45 ms |
90504 KB |
Output is correct |
8 |
Correct |
43 ms |
90236 KB |
Output is correct |
9 |
Correct |
29 ms |
59604 KB |
Output is correct |
10 |
Correct |
41 ms |
90152 KB |
Output is correct |
11 |
Correct |
42 ms |
90444 KB |
Output is correct |
12 |
Correct |
40 ms |
90436 KB |
Output is correct |
13 |
Correct |
28 ms |
59588 KB |
Output is correct |
14 |
Correct |
42 ms |
90560 KB |
Output is correct |
15 |
Correct |
28 ms |
59604 KB |
Output is correct |
16 |
Correct |
47 ms |
90636 KB |
Output is correct |
17 |
Correct |
31 ms |
59628 KB |
Output is correct |
18 |
Correct |
43 ms |
90548 KB |
Output is correct |
19 |
Correct |
41 ms |
90164 KB |
Output is correct |
20 |
Correct |
41 ms |
90400 KB |
Output is correct |
21 |
Correct |
40 ms |
90400 KB |
Output is correct |
22 |
Correct |
39 ms |
90176 KB |
Output is correct |
23 |
Correct |
41 ms |
90472 KB |
Output is correct |
24 |
Correct |
41 ms |
90172 KB |
Output is correct |
25 |
Correct |
45 ms |
90508 KB |
Output is correct |
26 |
Correct |
47 ms |
90572 KB |
Output is correct |
27 |
Correct |
42 ms |
90796 KB |
Output is correct |
28 |
Correct |
44 ms |
90520 KB |
Output is correct |
29 |
Correct |
44 ms |
90868 KB |
Output is correct |
30 |
Correct |
55 ms |
90448 KB |
Output is correct |
31 |
Correct |
48 ms |
90700 KB |
Output is correct |
32 |
Correct |
43 ms |
90488 KB |
Output is correct |
33 |
Correct |
41 ms |
90696 KB |
Output is correct |
34 |
Correct |
52 ms |
90696 KB |
Output is correct |
35 |
Correct |
44 ms |
75148 KB |
Output is correct |
36 |
Correct |
37 ms |
75124 KB |
Output is correct |
37 |
Correct |
35 ms |
75084 KB |
Output is correct |
38 |
Correct |
33 ms |
67276 KB |
Output is correct |
39 |
Correct |
32 ms |
67284 KB |
Output is correct |
40 |
Correct |
47 ms |
90468 KB |
Output is correct |
41 |
Correct |
34 ms |
67316 KB |
Output is correct |
42 |
Correct |
43 ms |
90460 KB |
Output is correct |
43 |
Correct |
46 ms |
90548 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
46 ms |
98056 KB |
Output is correct |
2 |
Correct |
40 ms |
67520 KB |
Output is correct |
3 |
Correct |
40 ms |
67536 KB |
Output is correct |
4 |
Correct |
46 ms |
67508 KB |
Output is correct |
5 |
Correct |
41 ms |
67532 KB |
Output is correct |
6 |
Correct |
40 ms |
67604 KB |
Output is correct |
7 |
Correct |
41 ms |
67532 KB |
Output is correct |
8 |
Correct |
41 ms |
67492 KB |
Output is correct |
9 |
Correct |
46 ms |
67532 KB |
Output is correct |
10 |
Correct |
40 ms |
67608 KB |
Output is correct |
11 |
Correct |
245 ms |
379372 KB |
Output is correct |
12 |
Correct |
39 ms |
67632 KB |
Output is correct |
13 |
Correct |
254 ms |
379368 KB |
Output is correct |
14 |
Correct |
36 ms |
67552 KB |
Output is correct |
15 |
Correct |
251 ms |
379296 KB |
Output is correct |
16 |
Correct |
273 ms |
379428 KB |
Output is correct |
17 |
Correct |
266 ms |
379432 KB |
Output is correct |
18 |
Correct |
282 ms |
379420 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
29 ms |
59604 KB |
Output is correct |
2 |
Correct |
32 ms |
59640 KB |
Output is correct |
3 |
Correct |
43 ms |
90540 KB |
Output is correct |
4 |
Correct |
47 ms |
90532 KB |
Output is correct |
5 |
Correct |
43 ms |
90444 KB |
Output is correct |
6 |
Correct |
44 ms |
90444 KB |
Output is correct |
7 |
Correct |
45 ms |
90504 KB |
Output is correct |
8 |
Correct |
43 ms |
90236 KB |
Output is correct |
9 |
Correct |
29 ms |
59604 KB |
Output is correct |
10 |
Correct |
41 ms |
90152 KB |
Output is correct |
11 |
Correct |
42 ms |
90444 KB |
Output is correct |
12 |
Correct |
40 ms |
90436 KB |
Output is correct |
13 |
Correct |
28 ms |
59588 KB |
Output is correct |
14 |
Correct |
42 ms |
90560 KB |
Output is correct |
15 |
Correct |
28 ms |
59604 KB |
Output is correct |
16 |
Correct |
47 ms |
90636 KB |
Output is correct |
17 |
Correct |
31 ms |
59628 KB |
Output is correct |
18 |
Correct |
43 ms |
90548 KB |
Output is correct |
19 |
Correct |
41 ms |
90164 KB |
Output is correct |
20 |
Correct |
41 ms |
90400 KB |
Output is correct |
21 |
Correct |
40 ms |
90400 KB |
Output is correct |
22 |
Correct |
39 ms |
90176 KB |
Output is correct |
23 |
Correct |
41 ms |
90472 KB |
Output is correct |
24 |
Correct |
41 ms |
90172 KB |
Output is correct |
25 |
Correct |
45 ms |
90508 KB |
Output is correct |
26 |
Correct |
47 ms |
90572 KB |
Output is correct |
27 |
Correct |
42 ms |
90796 KB |
Output is correct |
28 |
Correct |
44 ms |
90520 KB |
Output is correct |
29 |
Correct |
44 ms |
90868 KB |
Output is correct |
30 |
Correct |
55 ms |
90448 KB |
Output is correct |
31 |
Correct |
48 ms |
90700 KB |
Output is correct |
32 |
Correct |
43 ms |
90488 KB |
Output is correct |
33 |
Correct |
41 ms |
90696 KB |
Output is correct |
34 |
Correct |
52 ms |
90696 KB |
Output is correct |
35 |
Correct |
44 ms |
75148 KB |
Output is correct |
36 |
Correct |
37 ms |
75124 KB |
Output is correct |
37 |
Correct |
35 ms |
75084 KB |
Output is correct |
38 |
Correct |
33 ms |
67276 KB |
Output is correct |
39 |
Correct |
32 ms |
67284 KB |
Output is correct |
40 |
Correct |
47 ms |
90468 KB |
Output is correct |
41 |
Correct |
34 ms |
67316 KB |
Output is correct |
42 |
Correct |
43 ms |
90460 KB |
Output is correct |
43 |
Correct |
46 ms |
90548 KB |
Output is correct |
44 |
Correct |
226 ms |
110824 KB |
Output is correct |
45 |
Correct |
36 ms |
67492 KB |
Output is correct |
46 |
Correct |
55 ms |
98404 KB |
Output is correct |
47 |
Correct |
63 ms |
98564 KB |
Output is correct |
48 |
Correct |
59 ms |
98356 KB |
Output is correct |
49 |
Correct |
62 ms |
98508 KB |
Output is correct |
50 |
Correct |
70 ms |
98508 KB |
Output is correct |
51 |
Correct |
79 ms |
99120 KB |
Output is correct |
52 |
Correct |
41 ms |
90444 KB |
Output is correct |
53 |
Correct |
59 ms |
98964 KB |
Output is correct |
54 |
Correct |
89 ms |
99348 KB |
Output is correct |
55 |
Correct |
48 ms |
98280 KB |
Output is correct |
56 |
Correct |
47 ms |
90452 KB |
Output is correct |
57 |
Correct |
45 ms |
98072 KB |
Output is correct |
58 |
Correct |
70 ms |
98984 KB |
Output is correct |
59 |
Correct |
72 ms |
99256 KB |
Output is correct |
60 |
Correct |
50 ms |
98360 KB |
Output is correct |
61 |
Correct |
59 ms |
99212 KB |
Output is correct |
62 |
Correct |
61 ms |
99184 KB |
Output is correct |
63 |
Correct |
254 ms |
110792 KB |
Output is correct |
64 |
Correct |
149 ms |
104572 KB |
Output is correct |
65 |
Correct |
58 ms |
98300 KB |
Output is correct |
66 |
Correct |
78 ms |
99224 KB |
Output is correct |
67 |
Correct |
135 ms |
101680 KB |
Output is correct |
68 |
Correct |
170 ms |
104672 KB |
Output is correct |
69 |
Correct |
54 ms |
98380 KB |
Output is correct |
70 |
Correct |
67 ms |
98868 KB |
Output is correct |
71 |
Correct |
145 ms |
101668 KB |
Output is correct |
72 |
Correct |
100 ms |
100116 KB |
Output is correct |
73 |
Correct |
54 ms |
98260 KB |
Output is correct |
74 |
Correct |
67 ms |
98908 KB |
Output is correct |
75 |
Correct |
98 ms |
100156 KB |
Output is correct |
76 |
Correct |
54 ms |
98376 KB |
Output is correct |
77 |
Correct |
55 ms |
98636 KB |
Output is correct |
78 |
Correct |
51 ms |
98352 KB |
Output is correct |
79 |
Correct |
47 ms |
83016 KB |
Output is correct |
80 |
Correct |
53 ms |
98380 KB |
Output is correct |
81 |
Correct |
60 ms |
98592 KB |
Output is correct |
82 |
Correct |
42 ms |
75104 KB |
Output is correct |
83 |
Correct |
47 ms |
83032 KB |
Output is correct |
84 |
Correct |
63 ms |
98608 KB |
Output is correct |
85 |
Correct |
41 ms |
75112 KB |
Output is correct |
86 |
Correct |
67 ms |
98652 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
29 ms |
59604 KB |
Output is correct |
2 |
Correct |
32 ms |
59640 KB |
Output is correct |
3 |
Correct |
43 ms |
90540 KB |
Output is correct |
4 |
Correct |
47 ms |
90532 KB |
Output is correct |
5 |
Correct |
43 ms |
90444 KB |
Output is correct |
6 |
Correct |
44 ms |
90444 KB |
Output is correct |
7 |
Correct |
45 ms |
90504 KB |
Output is correct |
8 |
Correct |
43 ms |
90236 KB |
Output is correct |
9 |
Correct |
29 ms |
59604 KB |
Output is correct |
10 |
Correct |
41 ms |
90152 KB |
Output is correct |
11 |
Correct |
42 ms |
90444 KB |
Output is correct |
12 |
Correct |
40 ms |
90436 KB |
Output is correct |
13 |
Correct |
28 ms |
59588 KB |
Output is correct |
14 |
Correct |
42 ms |
90560 KB |
Output is correct |
15 |
Correct |
28 ms |
59604 KB |
Output is correct |
16 |
Correct |
47 ms |
90636 KB |
Output is correct |
17 |
Correct |
31 ms |
59628 KB |
Output is correct |
18 |
Correct |
43 ms |
90548 KB |
Output is correct |
19 |
Correct |
41 ms |
90164 KB |
Output is correct |
20 |
Correct |
41 ms |
90400 KB |
Output is correct |
21 |
Correct |
40 ms |
90400 KB |
Output is correct |
22 |
Correct |
39 ms |
90176 KB |
Output is correct |
23 |
Correct |
41 ms |
90472 KB |
Output is correct |
24 |
Correct |
41 ms |
90172 KB |
Output is correct |
25 |
Correct |
45 ms |
90508 KB |
Output is correct |
26 |
Correct |
47 ms |
90572 KB |
Output is correct |
27 |
Correct |
42 ms |
90796 KB |
Output is correct |
28 |
Correct |
44 ms |
90520 KB |
Output is correct |
29 |
Correct |
44 ms |
90868 KB |
Output is correct |
30 |
Correct |
55 ms |
90448 KB |
Output is correct |
31 |
Correct |
48 ms |
90700 KB |
Output is correct |
32 |
Correct |
43 ms |
90488 KB |
Output is correct |
33 |
Correct |
41 ms |
90696 KB |
Output is correct |
34 |
Correct |
52 ms |
90696 KB |
Output is correct |
35 |
Correct |
44 ms |
75148 KB |
Output is correct |
36 |
Correct |
37 ms |
75124 KB |
Output is correct |
37 |
Correct |
35 ms |
75084 KB |
Output is correct |
38 |
Correct |
33 ms |
67276 KB |
Output is correct |
39 |
Correct |
32 ms |
67284 KB |
Output is correct |
40 |
Correct |
47 ms |
90468 KB |
Output is correct |
41 |
Correct |
34 ms |
67316 KB |
Output is correct |
42 |
Correct |
43 ms |
90460 KB |
Output is correct |
43 |
Correct |
46 ms |
90548 KB |
Output is correct |
44 |
Correct |
37 ms |
67540 KB |
Output is correct |
45 |
Correct |
224 ms |
377420 KB |
Output is correct |
46 |
Correct |
201 ms |
377056 KB |
Output is correct |
47 |
Correct |
244 ms |
377428 KB |
Output is correct |
48 |
Correct |
241 ms |
377528 KB |
Output is correct |
49 |
Correct |
148 ms |
368548 KB |
Output is correct |
50 |
Correct |
213 ms |
377792 KB |
Output is correct |
51 |
Correct |
254 ms |
377384 KB |
Output is correct |
52 |
Correct |
164 ms |
376252 KB |
Output is correct |
53 |
Correct |
162 ms |
368616 KB |
Output is correct |
54 |
Correct |
147 ms |
373504 KB |
Output is correct |
55 |
Correct |
236 ms |
378032 KB |
Output is correct |
56 |
Correct |
156 ms |
368184 KB |
Output is correct |
57 |
Correct |
165 ms |
376172 KB |
Output is correct |
58 |
Correct |
237 ms |
379696 KB |
Output is correct |
59 |
Correct |
207 ms |
368040 KB |
Output is correct |
60 |
Correct |
182 ms |
375780 KB |
Output is correct |
61 |
Correct |
231 ms |
379708 KB |
Output is correct |
62 |
Correct |
195 ms |
377408 KB |
Output is correct |
63 |
Correct |
198 ms |
376832 KB |
Output is correct |
64 |
Correct |
188 ms |
375888 KB |
Output is correct |
65 |
Correct |
226 ms |
377700 KB |
Output is correct |
66 |
Correct |
219 ms |
377472 KB |
Output is correct |
67 |
Correct |
191 ms |
376836 KB |
Output is correct |
68 |
Correct |
239 ms |
377036 KB |
Output is correct |
69 |
Correct |
240 ms |
377748 KB |
Output is correct |
70 |
Correct |
191 ms |
376132 KB |
Output is correct |
71 |
Correct |
218 ms |
377100 KB |
Output is correct |
72 |
Correct |
191 ms |
376548 KB |
Output is correct |
73 |
Correct |
231 ms |
378536 KB |
Output is correct |
74 |
Correct |
186 ms |
376804 KB |
Output is correct |
75 |
Correct |
123 ms |
222508 KB |
Output is correct |
76 |
Correct |
185 ms |
377808 KB |
Output is correct |
77 |
Correct |
211 ms |
378672 KB |
Output is correct |
78 |
Correct |
141 ms |
223016 KB |
Output is correct |
79 |
Correct |
120 ms |
222512 KB |
Output is correct |
80 |
Correct |
72 ms |
144916 KB |
Output is correct |
81 |
Correct |
123 ms |
223012 KB |
Output is correct |
82 |
Correct |
194 ms |
377512 KB |
Output is correct |
83 |
Correct |
81 ms |
145004 KB |
Output is correct |
84 |
Correct |
203 ms |
377596 KB |
Output is correct |