/* 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;
int n, k;
vector<int> g[N], path;
vector<bool> vis(N);
bitset<50001> is[50001];
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();
}
void solve(){
cin >> n >> k;
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;
}
vector<vector<int>> v;
for(int i = 0; i < n; ++i) v.pb({i});
for(int j = 2; j <= k; ++j){
bitset<50001> in, out;
vector<vector<int>> t;
for(auto &u: v){
for(int x: u) in[x] = 1;
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){
u.pb(x);
t.pb(u);
u.pop_back();
}
}
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:120:16: warning: unused variable 'aa' [-Wunused-variable]
120 | int T = 1, aa;
| ^~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
23892 KB |
Output is correct |
2 |
Correct |
12 ms |
23972 KB |
Output is correct |
3 |
Correct |
21 ms |
44824 KB |
Output is correct |
4 |
Correct |
20 ms |
44244 KB |
Output is correct |
5 |
Correct |
20 ms |
44172 KB |
Output is correct |
6 |
Correct |
21 ms |
44256 KB |
Output is correct |
7 |
Correct |
20 ms |
44244 KB |
Output is correct |
8 |
Correct |
12 ms |
23892 KB |
Output is correct |
9 |
Correct |
12 ms |
23872 KB |
Output is correct |
10 |
Correct |
14 ms |
23872 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
23892 KB |
Output is correct |
2 |
Correct |
12 ms |
23972 KB |
Output is correct |
3 |
Correct |
21 ms |
44824 KB |
Output is correct |
4 |
Correct |
20 ms |
44244 KB |
Output is correct |
5 |
Correct |
20 ms |
44172 KB |
Output is correct |
6 |
Correct |
21 ms |
44256 KB |
Output is correct |
7 |
Correct |
20 ms |
44244 KB |
Output is correct |
8 |
Correct |
12 ms |
23892 KB |
Output is correct |
9 |
Correct |
12 ms |
23872 KB |
Output is correct |
10 |
Correct |
14 ms |
23872 KB |
Output is correct |
11 |
Correct |
21 ms |
44124 KB |
Output is correct |
12 |
Correct |
20 ms |
44180 KB |
Output is correct |
13 |
Correct |
13 ms |
23892 KB |
Output is correct |
14 |
Correct |
21 ms |
44092 KB |
Output is correct |
15 |
Correct |
13 ms |
23892 KB |
Output is correct |
16 |
Correct |
23 ms |
44168 KB |
Output is correct |
17 |
Correct |
14 ms |
23892 KB |
Output is correct |
18 |
Correct |
22 ms |
44244 KB |
Output is correct |
19 |
Correct |
14 ms |
23904 KB |
Output is correct |
20 |
Correct |
21 ms |
44092 KB |
Output is correct |
21 |
Correct |
24 ms |
44180 KB |
Output is correct |
22 |
Correct |
12 ms |
23892 KB |
Output is correct |
23 |
Correct |
22 ms |
45396 KB |
Output is correct |
24 |
Correct |
13 ms |
23892 KB |
Output is correct |
25 |
Correct |
22 ms |
45260 KB |
Output is correct |
26 |
Correct |
23 ms |
44672 KB |
Output is correct |
27 |
Correct |
24 ms |
45588 KB |
Output is correct |
28 |
Correct |
22 ms |
44560 KB |
Output is correct |
29 |
Correct |
23 ms |
45524 KB |
Output is correct |
30 |
Correct |
24 ms |
45108 KB |
Output is correct |
31 |
Correct |
22 ms |
45696 KB |
Output is correct |
32 |
Correct |
22 ms |
45036 KB |
Output is correct |
33 |
Correct |
22 ms |
45580 KB |
Output is correct |
34 |
Correct |
24 ms |
45780 KB |
Output is correct |
35 |
Correct |
19 ms |
34516 KB |
Output is correct |
36 |
Correct |
18 ms |
34448 KB |
Output is correct |
37 |
Correct |
19 ms |
34472 KB |
Output is correct |
38 |
Correct |
15 ms |
29012 KB |
Output is correct |
39 |
Correct |
16 ms |
29080 KB |
Output is correct |
40 |
Correct |
23 ms |
45900 KB |
Output is correct |
41 |
Correct |
15 ms |
29012 KB |
Output is correct |
42 |
Correct |
24 ms |
45928 KB |
Output is correct |
43 |
Correct |
22 ms |
45908 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
24276 KB |
Output is correct |
2 |
Correct |
15 ms |
24020 KB |
Output is correct |
3 |
Correct |
15 ms |
23980 KB |
Output is correct |
4 |
Correct |
13 ms |
24000 KB |
Output is correct |
5 |
Correct |
12 ms |
24020 KB |
Output is correct |
6 |
Correct |
16 ms |
24008 KB |
Output is correct |
7 |
Correct |
13 ms |
24020 KB |
Output is correct |
8 |
Correct |
13 ms |
23964 KB |
Output is correct |
9 |
Correct |
14 ms |
24020 KB |
Output is correct |
10 |
Correct |
14 ms |
23944 KB |
Output is correct |
11 |
Correct |
720 ms |
388532 KB |
Output is correct |
12 |
Correct |
14 ms |
23928 KB |
Output is correct |
13 |
Correct |
1182 ms |
401944 KB |
Output is correct |
14 |
Correct |
14 ms |
24020 KB |
Output is correct |
15 |
Correct |
625 ms |
388572 KB |
Output is correct |
16 |
Correct |
686 ms |
388400 KB |
Output is correct |
17 |
Correct |
1175 ms |
402112 KB |
Output is correct |
18 |
Correct |
743 ms |
388420 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
23892 KB |
Output is correct |
2 |
Correct |
12 ms |
23972 KB |
Output is correct |
3 |
Correct |
21 ms |
44824 KB |
Output is correct |
4 |
Correct |
20 ms |
44244 KB |
Output is correct |
5 |
Correct |
20 ms |
44172 KB |
Output is correct |
6 |
Correct |
21 ms |
44256 KB |
Output is correct |
7 |
Correct |
20 ms |
44244 KB |
Output is correct |
8 |
Correct |
12 ms |
23892 KB |
Output is correct |
9 |
Correct |
12 ms |
23872 KB |
Output is correct |
10 |
Correct |
14 ms |
23872 KB |
Output is correct |
11 |
Correct |
21 ms |
44124 KB |
Output is correct |
12 |
Correct |
20 ms |
44180 KB |
Output is correct |
13 |
Correct |
13 ms |
23892 KB |
Output is correct |
14 |
Correct |
21 ms |
44092 KB |
Output is correct |
15 |
Correct |
13 ms |
23892 KB |
Output is correct |
16 |
Correct |
23 ms |
44168 KB |
Output is correct |
17 |
Correct |
14 ms |
23892 KB |
Output is correct |
18 |
Correct |
22 ms |
44244 KB |
Output is correct |
19 |
Correct |
14 ms |
23904 KB |
Output is correct |
20 |
Correct |
21 ms |
44092 KB |
Output is correct |
21 |
Correct |
24 ms |
44180 KB |
Output is correct |
22 |
Correct |
12 ms |
23892 KB |
Output is correct |
23 |
Correct |
22 ms |
45396 KB |
Output is correct |
24 |
Correct |
13 ms |
23892 KB |
Output is correct |
25 |
Correct |
22 ms |
45260 KB |
Output is correct |
26 |
Correct |
23 ms |
44672 KB |
Output is correct |
27 |
Correct |
24 ms |
45588 KB |
Output is correct |
28 |
Correct |
22 ms |
44560 KB |
Output is correct |
29 |
Correct |
23 ms |
45524 KB |
Output is correct |
30 |
Correct |
24 ms |
45108 KB |
Output is correct |
31 |
Correct |
22 ms |
45696 KB |
Output is correct |
32 |
Correct |
22 ms |
45036 KB |
Output is correct |
33 |
Correct |
22 ms |
45580 KB |
Output is correct |
34 |
Correct |
24 ms |
45780 KB |
Output is correct |
35 |
Correct |
19 ms |
34516 KB |
Output is correct |
36 |
Correct |
18 ms |
34448 KB |
Output is correct |
37 |
Correct |
19 ms |
34472 KB |
Output is correct |
38 |
Correct |
15 ms |
29012 KB |
Output is correct |
39 |
Correct |
16 ms |
29080 KB |
Output is correct |
40 |
Correct |
23 ms |
45900 KB |
Output is correct |
41 |
Correct |
15 ms |
29012 KB |
Output is correct |
42 |
Correct |
24 ms |
45928 KB |
Output is correct |
43 |
Correct |
22 ms |
45908 KB |
Output is correct |
44 |
Runtime error |
1265 ms |
524288 KB |
Execution killed with signal 9 |
45 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
23892 KB |
Output is correct |
2 |
Correct |
12 ms |
23972 KB |
Output is correct |
3 |
Correct |
21 ms |
44824 KB |
Output is correct |
4 |
Correct |
20 ms |
44244 KB |
Output is correct |
5 |
Correct |
20 ms |
44172 KB |
Output is correct |
6 |
Correct |
21 ms |
44256 KB |
Output is correct |
7 |
Correct |
20 ms |
44244 KB |
Output is correct |
8 |
Correct |
12 ms |
23892 KB |
Output is correct |
9 |
Correct |
12 ms |
23872 KB |
Output is correct |
10 |
Correct |
14 ms |
23872 KB |
Output is correct |
11 |
Correct |
21 ms |
44124 KB |
Output is correct |
12 |
Correct |
20 ms |
44180 KB |
Output is correct |
13 |
Correct |
13 ms |
23892 KB |
Output is correct |
14 |
Correct |
21 ms |
44092 KB |
Output is correct |
15 |
Correct |
13 ms |
23892 KB |
Output is correct |
16 |
Correct |
23 ms |
44168 KB |
Output is correct |
17 |
Correct |
14 ms |
23892 KB |
Output is correct |
18 |
Correct |
22 ms |
44244 KB |
Output is correct |
19 |
Correct |
14 ms |
23904 KB |
Output is correct |
20 |
Correct |
21 ms |
44092 KB |
Output is correct |
21 |
Correct |
24 ms |
44180 KB |
Output is correct |
22 |
Correct |
12 ms |
23892 KB |
Output is correct |
23 |
Correct |
22 ms |
45396 KB |
Output is correct |
24 |
Correct |
13 ms |
23892 KB |
Output is correct |
25 |
Correct |
22 ms |
45260 KB |
Output is correct |
26 |
Correct |
23 ms |
44672 KB |
Output is correct |
27 |
Correct |
24 ms |
45588 KB |
Output is correct |
28 |
Correct |
22 ms |
44560 KB |
Output is correct |
29 |
Correct |
23 ms |
45524 KB |
Output is correct |
30 |
Correct |
24 ms |
45108 KB |
Output is correct |
31 |
Correct |
22 ms |
45696 KB |
Output is correct |
32 |
Correct |
22 ms |
45036 KB |
Output is correct |
33 |
Correct |
22 ms |
45580 KB |
Output is correct |
34 |
Correct |
24 ms |
45780 KB |
Output is correct |
35 |
Correct |
19 ms |
34516 KB |
Output is correct |
36 |
Correct |
18 ms |
34448 KB |
Output is correct |
37 |
Correct |
19 ms |
34472 KB |
Output is correct |
38 |
Correct |
15 ms |
29012 KB |
Output is correct |
39 |
Correct |
16 ms |
29080 KB |
Output is correct |
40 |
Correct |
23 ms |
45900 KB |
Output is correct |
41 |
Correct |
15 ms |
29012 KB |
Output is correct |
42 |
Correct |
24 ms |
45928 KB |
Output is correct |
43 |
Correct |
22 ms |
45908 KB |
Output is correct |
44 |
Correct |
13 ms |
23892 KB |
Output is correct |
45 |
Correct |
501 ms |
364232 KB |
Output is correct |
46 |
Execution timed out |
3112 ms |
319096 KB |
Time limit exceeded |
47 |
Halted |
0 ms |
0 KB |
- |