/* 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;
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 dfs2(int vv, int p){
vis[vv] = 1;
path.pb(vv);
for(int u: g[vv]){
if(u != p){
if(vis[u]){
if(path[path.size() - 3] == u){
v.pb({vv, path[path.size() - 2], path[path.size() - 3]});
}
}else{
dfs2(u, vv);
}
}
}
path.pop_back();
}
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(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;
}
for(int i = 0; i < n; ++i) for(int u: g[i]) if(u < i) v.pb(vector<int> {u, i});
for(int j = 3; 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:159:16: warning: unused variable 'aa' [-Wunused-variable]
159 | int T = 1, aa;
| ^~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
18 ms |
36228 KB |
Output is correct |
2 |
Correct |
22 ms |
36148 KB |
Output is correct |
3 |
Correct |
40 ms |
66932 KB |
Output is correct |
4 |
Correct |
31 ms |
66968 KB |
Output is correct |
5 |
Correct |
36 ms |
66900 KB |
Output is correct |
6 |
Correct |
30 ms |
66860 KB |
Output is correct |
7 |
Correct |
31 ms |
66968 KB |
Output is correct |
8 |
Correct |
29 ms |
66708 KB |
Output is correct |
9 |
Correct |
18 ms |
36124 KB |
Output is correct |
10 |
Correct |
33 ms |
66772 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
18 ms |
36228 KB |
Output is correct |
2 |
Correct |
22 ms |
36148 KB |
Output is correct |
3 |
Correct |
40 ms |
66932 KB |
Output is correct |
4 |
Correct |
31 ms |
66968 KB |
Output is correct |
5 |
Correct |
36 ms |
66900 KB |
Output is correct |
6 |
Correct |
30 ms |
66860 KB |
Output is correct |
7 |
Correct |
31 ms |
66968 KB |
Output is correct |
8 |
Correct |
29 ms |
66708 KB |
Output is correct |
9 |
Correct |
18 ms |
36124 KB |
Output is correct |
10 |
Correct |
33 ms |
66772 KB |
Output is correct |
11 |
Correct |
30 ms |
66888 KB |
Output is correct |
12 |
Correct |
34 ms |
66940 KB |
Output is correct |
13 |
Correct |
20 ms |
36120 KB |
Output is correct |
14 |
Correct |
31 ms |
66844 KB |
Output is correct |
15 |
Correct |
18 ms |
36192 KB |
Output is correct |
16 |
Correct |
32 ms |
66924 KB |
Output is correct |
17 |
Correct |
20 ms |
36180 KB |
Output is correct |
18 |
Correct |
32 ms |
66964 KB |
Output is correct |
19 |
Correct |
32 ms |
66692 KB |
Output is correct |
20 |
Correct |
31 ms |
66896 KB |
Output is correct |
21 |
Correct |
31 ms |
66900 KB |
Output is correct |
22 |
Correct |
30 ms |
66724 KB |
Output is correct |
23 |
Correct |
31 ms |
66884 KB |
Output is correct |
24 |
Correct |
30 ms |
66688 KB |
Output is correct |
25 |
Correct |
34 ms |
66952 KB |
Output is correct |
26 |
Correct |
31 ms |
67028 KB |
Output is correct |
27 |
Correct |
32 ms |
67292 KB |
Output is correct |
28 |
Correct |
31 ms |
67048 KB |
Output is correct |
29 |
Correct |
32 ms |
67304 KB |
Output is correct |
30 |
Correct |
34 ms |
66944 KB |
Output is correct |
31 |
Correct |
31 ms |
67156 KB |
Output is correct |
32 |
Correct |
31 ms |
66864 KB |
Output is correct |
33 |
Correct |
35 ms |
67040 KB |
Output is correct |
34 |
Correct |
34 ms |
67160 KB |
Output is correct |
35 |
Correct |
26 ms |
51592 KB |
Output is correct |
36 |
Correct |
26 ms |
51668 KB |
Output is correct |
37 |
Correct |
29 ms |
51572 KB |
Output is correct |
38 |
Correct |
22 ms |
43772 KB |
Output is correct |
39 |
Correct |
25 ms |
43828 KB |
Output is correct |
40 |
Correct |
32 ms |
66992 KB |
Output is correct |
41 |
Correct |
21 ms |
43808 KB |
Output is correct |
42 |
Correct |
33 ms |
66912 KB |
Output is correct |
43 |
Correct |
39 ms |
66876 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
41 ms |
74620 KB |
Output is correct |
2 |
Correct |
30 ms |
44116 KB |
Output is correct |
3 |
Correct |
28 ms |
44040 KB |
Output is correct |
4 |
Correct |
32 ms |
43984 KB |
Output is correct |
5 |
Correct |
29 ms |
44112 KB |
Output is correct |
6 |
Correct |
30 ms |
44120 KB |
Output is correct |
7 |
Correct |
29 ms |
44096 KB |
Output is correct |
8 |
Correct |
29 ms |
44120 KB |
Output is correct |
9 |
Correct |
30 ms |
44132 KB |
Output is correct |
10 |
Correct |
29 ms |
44016 KB |
Output is correct |
11 |
Correct |
458 ms |
366200 KB |
Output is correct |
12 |
Correct |
28 ms |
44108 KB |
Output is correct |
13 |
Correct |
417 ms |
366368 KB |
Output is correct |
14 |
Correct |
30 ms |
44044 KB |
Output is correct |
15 |
Correct |
408 ms |
366332 KB |
Output is correct |
16 |
Correct |
424 ms |
366324 KB |
Output is correct |
17 |
Correct |
448 ms |
366428 KB |
Output is correct |
18 |
Correct |
423 ms |
366324 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
18 ms |
36228 KB |
Output is correct |
2 |
Correct |
22 ms |
36148 KB |
Output is correct |
3 |
Correct |
40 ms |
66932 KB |
Output is correct |
4 |
Correct |
31 ms |
66968 KB |
Output is correct |
5 |
Correct |
36 ms |
66900 KB |
Output is correct |
6 |
Correct |
30 ms |
66860 KB |
Output is correct |
7 |
Correct |
31 ms |
66968 KB |
Output is correct |
8 |
Correct |
29 ms |
66708 KB |
Output is correct |
9 |
Correct |
18 ms |
36124 KB |
Output is correct |
10 |
Correct |
33 ms |
66772 KB |
Output is correct |
11 |
Correct |
30 ms |
66888 KB |
Output is correct |
12 |
Correct |
34 ms |
66940 KB |
Output is correct |
13 |
Correct |
20 ms |
36120 KB |
Output is correct |
14 |
Correct |
31 ms |
66844 KB |
Output is correct |
15 |
Correct |
18 ms |
36192 KB |
Output is correct |
16 |
Correct |
32 ms |
66924 KB |
Output is correct |
17 |
Correct |
20 ms |
36180 KB |
Output is correct |
18 |
Correct |
32 ms |
66964 KB |
Output is correct |
19 |
Correct |
32 ms |
66692 KB |
Output is correct |
20 |
Correct |
31 ms |
66896 KB |
Output is correct |
21 |
Correct |
31 ms |
66900 KB |
Output is correct |
22 |
Correct |
30 ms |
66724 KB |
Output is correct |
23 |
Correct |
31 ms |
66884 KB |
Output is correct |
24 |
Correct |
30 ms |
66688 KB |
Output is correct |
25 |
Correct |
34 ms |
66952 KB |
Output is correct |
26 |
Correct |
31 ms |
67028 KB |
Output is correct |
27 |
Correct |
32 ms |
67292 KB |
Output is correct |
28 |
Correct |
31 ms |
67048 KB |
Output is correct |
29 |
Correct |
32 ms |
67304 KB |
Output is correct |
30 |
Correct |
34 ms |
66944 KB |
Output is correct |
31 |
Correct |
31 ms |
67156 KB |
Output is correct |
32 |
Correct |
31 ms |
66864 KB |
Output is correct |
33 |
Correct |
35 ms |
67040 KB |
Output is correct |
34 |
Correct |
34 ms |
67160 KB |
Output is correct |
35 |
Correct |
26 ms |
51592 KB |
Output is correct |
36 |
Correct |
26 ms |
51668 KB |
Output is correct |
37 |
Correct |
29 ms |
51572 KB |
Output is correct |
38 |
Correct |
22 ms |
43772 KB |
Output is correct |
39 |
Correct |
25 ms |
43828 KB |
Output is correct |
40 |
Correct |
32 ms |
66992 KB |
Output is correct |
41 |
Correct |
21 ms |
43808 KB |
Output is correct |
42 |
Correct |
33 ms |
66912 KB |
Output is correct |
43 |
Correct |
39 ms |
66876 KB |
Output is correct |
44 |
Correct |
250 ms |
87124 KB |
Output is correct |
45 |
Correct |
27 ms |
44036 KB |
Output is correct |
46 |
Correct |
49 ms |
75388 KB |
Output is correct |
47 |
Correct |
61 ms |
76144 KB |
Output is correct |
48 |
Correct |
55 ms |
75400 KB |
Output is correct |
49 |
Correct |
58 ms |
76184 KB |
Output is correct |
50 |
Correct |
59 ms |
76092 KB |
Output is correct |
51 |
Correct |
106 ms |
77872 KB |
Output is correct |
52 |
Correct |
32 ms |
66964 KB |
Output is correct |
53 |
Correct |
1855 ms |
77700 KB |
Output is correct |
54 |
Correct |
134 ms |
77792 KB |
Output is correct |
55 |
Correct |
60 ms |
75216 KB |
Output is correct |
56 |
Correct |
38 ms |
66952 KB |
Output is correct |
57 |
Correct |
42 ms |
74572 KB |
Output is correct |
58 |
Correct |
1840 ms |
77712 KB |
Output is correct |
59 |
Correct |
56 ms |
75916 KB |
Output is correct |
60 |
Correct |
44 ms |
75032 KB |
Output is correct |
61 |
Correct |
55 ms |
75940 KB |
Output is correct |
62 |
Correct |
62 ms |
75932 KB |
Output is correct |
63 |
Correct |
239 ms |
87080 KB |
Output is correct |
64 |
Correct |
155 ms |
81524 KB |
Output is correct |
65 |
Correct |
47 ms |
75340 KB |
Output is correct |
66 |
Correct |
55 ms |
75972 KB |
Output is correct |
67 |
Correct |
142 ms |
77732 KB |
Output is correct |
68 |
Correct |
154 ms |
81440 KB |
Output is correct |
69 |
Correct |
47 ms |
75456 KB |
Output is correct |
70 |
Correct |
66 ms |
76176 KB |
Output is correct |
71 |
Correct |
137 ms |
77748 KB |
Output is correct |
72 |
Correct |
113 ms |
76760 KB |
Output is correct |
73 |
Correct |
43 ms |
75096 KB |
Output is correct |
74 |
Correct |
66 ms |
76164 KB |
Output is correct |
75 |
Correct |
101 ms |
76872 KB |
Output is correct |
76 |
Correct |
104 ms |
75524 KB |
Output is correct |
77 |
Correct |
71 ms |
76548 KB |
Output is correct |
78 |
Correct |
52 ms |
75080 KB |
Output is correct |
79 |
Correct |
44 ms |
60240 KB |
Output is correct |
80 |
Correct |
102 ms |
75524 KB |
Output is correct |
81 |
Correct |
61 ms |
76480 KB |
Output is correct |
82 |
Correct |
32 ms |
51796 KB |
Output is correct |
83 |
Correct |
42 ms |
60304 KB |
Output is correct |
84 |
Correct |
67 ms |
76240 KB |
Output is correct |
85 |
Correct |
33 ms |
51728 KB |
Output is correct |
86 |
Correct |
61 ms |
76236 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
18 ms |
36228 KB |
Output is correct |
2 |
Correct |
22 ms |
36148 KB |
Output is correct |
3 |
Correct |
40 ms |
66932 KB |
Output is correct |
4 |
Correct |
31 ms |
66968 KB |
Output is correct |
5 |
Correct |
36 ms |
66900 KB |
Output is correct |
6 |
Correct |
30 ms |
66860 KB |
Output is correct |
7 |
Correct |
31 ms |
66968 KB |
Output is correct |
8 |
Correct |
29 ms |
66708 KB |
Output is correct |
9 |
Correct |
18 ms |
36124 KB |
Output is correct |
10 |
Correct |
33 ms |
66772 KB |
Output is correct |
11 |
Correct |
30 ms |
66888 KB |
Output is correct |
12 |
Correct |
34 ms |
66940 KB |
Output is correct |
13 |
Correct |
20 ms |
36120 KB |
Output is correct |
14 |
Correct |
31 ms |
66844 KB |
Output is correct |
15 |
Correct |
18 ms |
36192 KB |
Output is correct |
16 |
Correct |
32 ms |
66924 KB |
Output is correct |
17 |
Correct |
20 ms |
36180 KB |
Output is correct |
18 |
Correct |
32 ms |
66964 KB |
Output is correct |
19 |
Correct |
32 ms |
66692 KB |
Output is correct |
20 |
Correct |
31 ms |
66896 KB |
Output is correct |
21 |
Correct |
31 ms |
66900 KB |
Output is correct |
22 |
Correct |
30 ms |
66724 KB |
Output is correct |
23 |
Correct |
31 ms |
66884 KB |
Output is correct |
24 |
Correct |
30 ms |
66688 KB |
Output is correct |
25 |
Correct |
34 ms |
66952 KB |
Output is correct |
26 |
Correct |
31 ms |
67028 KB |
Output is correct |
27 |
Correct |
32 ms |
67292 KB |
Output is correct |
28 |
Correct |
31 ms |
67048 KB |
Output is correct |
29 |
Correct |
32 ms |
67304 KB |
Output is correct |
30 |
Correct |
34 ms |
66944 KB |
Output is correct |
31 |
Correct |
31 ms |
67156 KB |
Output is correct |
32 |
Correct |
31 ms |
66864 KB |
Output is correct |
33 |
Correct |
35 ms |
67040 KB |
Output is correct |
34 |
Correct |
34 ms |
67160 KB |
Output is correct |
35 |
Correct |
26 ms |
51592 KB |
Output is correct |
36 |
Correct |
26 ms |
51668 KB |
Output is correct |
37 |
Correct |
29 ms |
51572 KB |
Output is correct |
38 |
Correct |
22 ms |
43772 KB |
Output is correct |
39 |
Correct |
25 ms |
43828 KB |
Output is correct |
40 |
Correct |
32 ms |
66992 KB |
Output is correct |
41 |
Correct |
21 ms |
43808 KB |
Output is correct |
42 |
Correct |
33 ms |
66912 KB |
Output is correct |
43 |
Correct |
39 ms |
66876 KB |
Output is correct |
44 |
Correct |
27 ms |
43988 KB |
Output is correct |
45 |
Correct |
339 ms |
362608 KB |
Output is correct |
46 |
Execution timed out |
3032 ms |
356780 KB |
Time limit exceeded |
47 |
Halted |
0 ms |
0 KB |
- |