/* 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 = 9900047;
int n, k;
vector<int> g[N], path;
vector<bool> vis(N);
vector<bitset<50001>> 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){
if(a < 0) a += MO;
return a >= MO ? a - MO : a;
}
void solve(){
cin >> n >> k;
is.resize(n+1);
int a = 0;
for(int i = 0; i < n; ++i){
int d; cin >> d; a += d;
for(int j = 0; j < d; ++j){
int x; cin >> x; g[i].pb(x); is[i][x] = 1;
}
}
if(a > N){
cout << 1;
return;
}
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] * 3) % MO;
vector<vector<int>> v;
for(int i = 0; i < n; ++i) v.pb({i});
for(int j = 2; j <= k; ++j){
bitset<50001> out, in;
vector<vector<int>> t;
bitset<N*10> m;
for(auto &u: v){
ll h = 0;
for(int x: u) in[x] = 1, h += e[x];
h = mod(h%MO);
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:143:16: warning: unused variable 'aa' [-Wunused-variable]
143 | int T = 1, aa;
| ^~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
25172 KB |
Output is correct |
2 |
Correct |
14 ms |
25180 KB |
Output is correct |
3 |
Correct |
29 ms |
55928 KB |
Output is correct |
4 |
Correct |
26 ms |
56020 KB |
Output is correct |
5 |
Correct |
28 ms |
55936 KB |
Output is correct |
6 |
Correct |
28 ms |
56012 KB |
Output is correct |
7 |
Correct |
28 ms |
56020 KB |
Output is correct |
8 |
Correct |
26 ms |
55764 KB |
Output is correct |
9 |
Correct |
14 ms |
25104 KB |
Output is correct |
10 |
Correct |
27 ms |
55736 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
25172 KB |
Output is correct |
2 |
Correct |
14 ms |
25180 KB |
Output is correct |
3 |
Correct |
29 ms |
55928 KB |
Output is correct |
4 |
Correct |
26 ms |
56020 KB |
Output is correct |
5 |
Correct |
28 ms |
55936 KB |
Output is correct |
6 |
Correct |
28 ms |
56012 KB |
Output is correct |
7 |
Correct |
28 ms |
56020 KB |
Output is correct |
8 |
Correct |
26 ms |
55764 KB |
Output is correct |
9 |
Correct |
14 ms |
25104 KB |
Output is correct |
10 |
Correct |
27 ms |
55736 KB |
Output is correct |
11 |
Correct |
26 ms |
56020 KB |
Output is correct |
12 |
Correct |
32 ms |
56020 KB |
Output is correct |
13 |
Correct |
16 ms |
25172 KB |
Output is correct |
14 |
Correct |
30 ms |
55896 KB |
Output is correct |
15 |
Correct |
16 ms |
25140 KB |
Output is correct |
16 |
Correct |
28 ms |
55964 KB |
Output is correct |
17 |
Correct |
15 ms |
25168 KB |
Output is correct |
18 |
Correct |
31 ms |
55984 KB |
Output is correct |
19 |
Correct |
30 ms |
55688 KB |
Output is correct |
20 |
Correct |
33 ms |
55892 KB |
Output is correct |
21 |
Correct |
30 ms |
55880 KB |
Output is correct |
22 |
Correct |
27 ms |
55708 KB |
Output is correct |
23 |
Correct |
37 ms |
56028 KB |
Output is correct |
24 |
Correct |
25 ms |
55764 KB |
Output is correct |
25 |
Correct |
28 ms |
55976 KB |
Output is correct |
26 |
Correct |
28 ms |
56040 KB |
Output is correct |
27 |
Correct |
28 ms |
56268 KB |
Output is correct |
28 |
Correct |
29 ms |
56016 KB |
Output is correct |
29 |
Correct |
35 ms |
56280 KB |
Output is correct |
30 |
Correct |
29 ms |
56024 KB |
Output is correct |
31 |
Correct |
37 ms |
56212 KB |
Output is correct |
32 |
Correct |
31 ms |
55940 KB |
Output is correct |
33 |
Correct |
33 ms |
56140 KB |
Output is correct |
34 |
Correct |
34 ms |
56232 KB |
Output is correct |
35 |
Correct |
21 ms |
40660 KB |
Output is correct |
36 |
Correct |
21 ms |
40680 KB |
Output is correct |
37 |
Correct |
25 ms |
40600 KB |
Output is correct |
38 |
Correct |
18 ms |
32840 KB |
Output is correct |
39 |
Correct |
18 ms |
32852 KB |
Output is correct |
40 |
Correct |
33 ms |
55972 KB |
Output is correct |
41 |
Correct |
20 ms |
32860 KB |
Output is correct |
42 |
Correct |
33 ms |
56044 KB |
Output is correct |
43 |
Correct |
34 ms |
56012 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
35 ms |
63960 KB |
Output is correct |
2 |
Correct |
23 ms |
33048 KB |
Output is correct |
3 |
Correct |
21 ms |
33112 KB |
Output is correct |
4 |
Correct |
24 ms |
32972 KB |
Output is correct |
5 |
Correct |
23 ms |
33104 KB |
Output is correct |
6 |
Correct |
22 ms |
33060 KB |
Output is correct |
7 |
Correct |
22 ms |
33048 KB |
Output is correct |
8 |
Correct |
22 ms |
33132 KB |
Output is correct |
9 |
Correct |
23 ms |
33056 KB |
Output is correct |
10 |
Correct |
21 ms |
33108 KB |
Output is correct |
11 |
Correct |
466 ms |
371816 KB |
Output is correct |
12 |
Correct |
23 ms |
33108 KB |
Output is correct |
13 |
Correct |
529 ms |
371564 KB |
Output is correct |
14 |
Correct |
25 ms |
33108 KB |
Output is correct |
15 |
Correct |
472 ms |
371580 KB |
Output is correct |
16 |
Correct |
476 ms |
371028 KB |
Output is correct |
17 |
Correct |
447 ms |
370980 KB |
Output is correct |
18 |
Correct |
471 ms |
370900 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
25172 KB |
Output is correct |
2 |
Correct |
14 ms |
25180 KB |
Output is correct |
3 |
Correct |
29 ms |
55928 KB |
Output is correct |
4 |
Correct |
26 ms |
56020 KB |
Output is correct |
5 |
Correct |
28 ms |
55936 KB |
Output is correct |
6 |
Correct |
28 ms |
56012 KB |
Output is correct |
7 |
Correct |
28 ms |
56020 KB |
Output is correct |
8 |
Correct |
26 ms |
55764 KB |
Output is correct |
9 |
Correct |
14 ms |
25104 KB |
Output is correct |
10 |
Correct |
27 ms |
55736 KB |
Output is correct |
11 |
Correct |
26 ms |
56020 KB |
Output is correct |
12 |
Correct |
32 ms |
56020 KB |
Output is correct |
13 |
Correct |
16 ms |
25172 KB |
Output is correct |
14 |
Correct |
30 ms |
55896 KB |
Output is correct |
15 |
Correct |
16 ms |
25140 KB |
Output is correct |
16 |
Correct |
28 ms |
55964 KB |
Output is correct |
17 |
Correct |
15 ms |
25168 KB |
Output is correct |
18 |
Correct |
31 ms |
55984 KB |
Output is correct |
19 |
Correct |
30 ms |
55688 KB |
Output is correct |
20 |
Correct |
33 ms |
55892 KB |
Output is correct |
21 |
Correct |
30 ms |
55880 KB |
Output is correct |
22 |
Correct |
27 ms |
55708 KB |
Output is correct |
23 |
Correct |
37 ms |
56028 KB |
Output is correct |
24 |
Correct |
25 ms |
55764 KB |
Output is correct |
25 |
Correct |
28 ms |
55976 KB |
Output is correct |
26 |
Correct |
28 ms |
56040 KB |
Output is correct |
27 |
Correct |
28 ms |
56268 KB |
Output is correct |
28 |
Correct |
29 ms |
56016 KB |
Output is correct |
29 |
Correct |
35 ms |
56280 KB |
Output is correct |
30 |
Correct |
29 ms |
56024 KB |
Output is correct |
31 |
Correct |
37 ms |
56212 KB |
Output is correct |
32 |
Correct |
31 ms |
55940 KB |
Output is correct |
33 |
Correct |
33 ms |
56140 KB |
Output is correct |
34 |
Correct |
34 ms |
56232 KB |
Output is correct |
35 |
Correct |
21 ms |
40660 KB |
Output is correct |
36 |
Correct |
21 ms |
40680 KB |
Output is correct |
37 |
Correct |
25 ms |
40600 KB |
Output is correct |
38 |
Correct |
18 ms |
32840 KB |
Output is correct |
39 |
Correct |
18 ms |
32852 KB |
Output is correct |
40 |
Correct |
33 ms |
55972 KB |
Output is correct |
41 |
Correct |
20 ms |
32860 KB |
Output is correct |
42 |
Correct |
33 ms |
56044 KB |
Output is correct |
43 |
Correct |
34 ms |
56012 KB |
Output is correct |
44 |
Correct |
216 ms |
76272 KB |
Output is correct |
45 |
Correct |
25 ms |
33084 KB |
Output is correct |
46 |
Correct |
47 ms |
65268 KB |
Output is correct |
47 |
Correct |
64 ms |
66436 KB |
Output is correct |
48 |
Correct |
58 ms |
65240 KB |
Output is correct |
49 |
Correct |
56 ms |
66564 KB |
Output is correct |
50 |
Correct |
56 ms |
66436 KB |
Output is correct |
51 |
Correct |
93 ms |
69068 KB |
Output is correct |
52 |
Correct |
36 ms |
56012 KB |
Output is correct |
53 |
Correct |
1861 ms |
69740 KB |
Output is correct |
54 |
Correct |
114 ms |
69800 KB |
Output is correct |
55 |
Correct |
42 ms |
64472 KB |
Output is correct |
56 |
Correct |
28 ms |
56032 KB |
Output is correct |
57 |
Correct |
34 ms |
63844 KB |
Output is correct |
58 |
Correct |
1848 ms |
69796 KB |
Output is correct |
59 |
Correct |
51 ms |
65140 KB |
Output is correct |
60 |
Correct |
50 ms |
64432 KB |
Output is correct |
61 |
Correct |
64 ms |
65224 KB |
Output is correct |
62 |
Correct |
50 ms |
65216 KB |
Output is correct |
63 |
Correct |
216 ms |
76260 KB |
Output is correct |
64 |
Correct |
140 ms |
70688 KB |
Output is correct |
65 |
Correct |
45 ms |
65032 KB |
Output is correct |
66 |
Correct |
49 ms |
65516 KB |
Output is correct |
67 |
Correct |
150 ms |
67052 KB |
Output is correct |
68 |
Correct |
165 ms |
70672 KB |
Output is correct |
69 |
Correct |
49 ms |
65140 KB |
Output is correct |
70 |
Correct |
62 ms |
66172 KB |
Output is correct |
71 |
Correct |
123 ms |
67032 KB |
Output is correct |
72 |
Correct |
98 ms |
66896 KB |
Output is correct |
73 |
Correct |
43 ms |
64340 KB |
Output is correct |
74 |
Correct |
80 ms |
66224 KB |
Output is correct |
75 |
Correct |
93 ms |
66948 KB |
Output is correct |
76 |
Correct |
89 ms |
65600 KB |
Output is correct |
77 |
Correct |
61 ms |
67592 KB |
Output is correct |
78 |
Correct |
40 ms |
64460 KB |
Output is correct |
79 |
Correct |
44 ms |
50328 KB |
Output is correct |
80 |
Correct |
96 ms |
65648 KB |
Output is correct |
81 |
Correct |
69 ms |
67604 KB |
Output is correct |
82 |
Correct |
31 ms |
41036 KB |
Output is correct |
83 |
Correct |
41 ms |
50312 KB |
Output is correct |
84 |
Correct |
65 ms |
66848 KB |
Output is correct |
85 |
Correct |
28 ms |
40936 KB |
Output is correct |
86 |
Correct |
59 ms |
66876 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
25172 KB |
Output is correct |
2 |
Correct |
14 ms |
25180 KB |
Output is correct |
3 |
Correct |
29 ms |
55928 KB |
Output is correct |
4 |
Correct |
26 ms |
56020 KB |
Output is correct |
5 |
Correct |
28 ms |
55936 KB |
Output is correct |
6 |
Correct |
28 ms |
56012 KB |
Output is correct |
7 |
Correct |
28 ms |
56020 KB |
Output is correct |
8 |
Correct |
26 ms |
55764 KB |
Output is correct |
9 |
Correct |
14 ms |
25104 KB |
Output is correct |
10 |
Correct |
27 ms |
55736 KB |
Output is correct |
11 |
Correct |
26 ms |
56020 KB |
Output is correct |
12 |
Correct |
32 ms |
56020 KB |
Output is correct |
13 |
Correct |
16 ms |
25172 KB |
Output is correct |
14 |
Correct |
30 ms |
55896 KB |
Output is correct |
15 |
Correct |
16 ms |
25140 KB |
Output is correct |
16 |
Correct |
28 ms |
55964 KB |
Output is correct |
17 |
Correct |
15 ms |
25168 KB |
Output is correct |
18 |
Correct |
31 ms |
55984 KB |
Output is correct |
19 |
Correct |
30 ms |
55688 KB |
Output is correct |
20 |
Correct |
33 ms |
55892 KB |
Output is correct |
21 |
Correct |
30 ms |
55880 KB |
Output is correct |
22 |
Correct |
27 ms |
55708 KB |
Output is correct |
23 |
Correct |
37 ms |
56028 KB |
Output is correct |
24 |
Correct |
25 ms |
55764 KB |
Output is correct |
25 |
Correct |
28 ms |
55976 KB |
Output is correct |
26 |
Correct |
28 ms |
56040 KB |
Output is correct |
27 |
Correct |
28 ms |
56268 KB |
Output is correct |
28 |
Correct |
29 ms |
56016 KB |
Output is correct |
29 |
Correct |
35 ms |
56280 KB |
Output is correct |
30 |
Correct |
29 ms |
56024 KB |
Output is correct |
31 |
Correct |
37 ms |
56212 KB |
Output is correct |
32 |
Correct |
31 ms |
55940 KB |
Output is correct |
33 |
Correct |
33 ms |
56140 KB |
Output is correct |
34 |
Correct |
34 ms |
56232 KB |
Output is correct |
35 |
Correct |
21 ms |
40660 KB |
Output is correct |
36 |
Correct |
21 ms |
40680 KB |
Output is correct |
37 |
Correct |
25 ms |
40600 KB |
Output is correct |
38 |
Correct |
18 ms |
32840 KB |
Output is correct |
39 |
Correct |
18 ms |
32852 KB |
Output is correct |
40 |
Correct |
33 ms |
55972 KB |
Output is correct |
41 |
Correct |
20 ms |
32860 KB |
Output is correct |
42 |
Correct |
33 ms |
56044 KB |
Output is correct |
43 |
Correct |
34 ms |
56012 KB |
Output is correct |
44 |
Correct |
22 ms |
32984 KB |
Output is correct |
45 |
Correct |
343 ms |
360940 KB |
Output is correct |
46 |
Execution timed out |
3080 ms |
352044 KB |
Time limit exceeded |
47 |
Halted |
0 ms |
0 KB |
- |