#include <bits/stdc++.h>
#define f first
#define s second
#define pb push_back
#define sz(x) ((int)((x).size()))
#define le(vec) vec[vec.size()-1]
#define all(x) (x).begin(), (x).end()
#define TSTS int ttt; cin >> ttt; while(ttt--) solve()
#define FAST_IO ios_base::sync_with_stdio(0); cin.tie(nullptr)
#define FOR(i, begin, end) for(int i = (begin); i < (end); i++)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef map<int, int> mii;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef pair<long double, long double> pdd;
const int INF=1e9, MOD=1e9+7, mod=998244353;
const ll LINF=1e18;
void setIO()
{
FAST_IO;
}
void setIO(string s)
{
FAST_IO;
freopen((s+".in").c_str(), "r", stdin);
freopen((s+".out").c_str(), "w", stdout);
}
const int N=5e4+10;
int n, k, d[N];
vi ad[N];
bool v[N];
bool three=false;
void dfs(int u, int prv=-1)
{
v[u]=true;
for(auto it : ad[u]){
if(!v[it]){
d[it]=d[u]+1;
dfs(it, u);
}
else if(it!=prv && d[it]!=-1 && d[u]-d[it]==2){
three=true;
}
}
d[u]=-1;
}
map<vi, int> cn;
vi now;
int ans;
void rec(vi &ar, int in=-1, int siz=0)
{
if(in!=-1){
now.pb(ar[in]);
cn[now]++;
if(cn[now]>=siz){
ans=max(ans, siz);
}
}
FOR(i, in+1, sz(ar))
{
rec(ar, i, siz+1);
}
if(!now.empty()) now.pop_back();
}
int main()
{
setIO();
cin >> n >> k;
bool all=true;
vi inf[n];
FOR(i, 0, n)
{
int x; cin >> x;
if(x!=0){
all=false;
}
inf[i].pb(i);
FOR(j, 0, x)
{
int u; cin >> u;
ad[i].pb(u);
inf[i].pb(u);
}
sort(all(inf[i]));
}
if(k<=3){
FOR(i, 0, n)
{
if(!v[i]){
d[i]=0;
dfs(i);
}
}
if(three){
cout << 3 << '\n';
}
else if(!all){
cout << 2 << '\n';
}
else{
cout << 1 << '\n';
}
}
else{
FOR(i, 0, n)
{
rec(inf[i]);
}
cout << ans;
}
}
Compilation message
politicaldevelopment.cpp: In function 'void setIO(std::string)':
politicaldevelopment.cpp:32:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
32 | freopen((s+".in").c_str(), "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
politicaldevelopment.cpp:33:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
33 | freopen((s+".out").c_str(), "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
1880 KB |
Output is correct |
2 |
Correct |
1 ms |
1624 KB |
Output is correct |
3 |
Correct |
3 ms |
2140 KB |
Output is correct |
4 |
Correct |
2 ms |
2140 KB |
Output is correct |
5 |
Correct |
3 ms |
2140 KB |
Output is correct |
6 |
Correct |
2 ms |
2140 KB |
Output is correct |
7 |
Correct |
2 ms |
2140 KB |
Output is correct |
8 |
Correct |
1 ms |
2136 KB |
Output is correct |
9 |
Correct |
1 ms |
1628 KB |
Output is correct |
10 |
Correct |
1 ms |
1904 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
1880 KB |
Output is correct |
2 |
Correct |
1 ms |
1624 KB |
Output is correct |
3 |
Correct |
3 ms |
2140 KB |
Output is correct |
4 |
Correct |
2 ms |
2140 KB |
Output is correct |
5 |
Correct |
3 ms |
2140 KB |
Output is correct |
6 |
Correct |
2 ms |
2140 KB |
Output is correct |
7 |
Correct |
2 ms |
2140 KB |
Output is correct |
8 |
Correct |
1 ms |
2136 KB |
Output is correct |
9 |
Correct |
1 ms |
1628 KB |
Output is correct |
10 |
Correct |
1 ms |
1904 KB |
Output is correct |
11 |
Correct |
3 ms |
2136 KB |
Output is correct |
12 |
Correct |
2 ms |
2140 KB |
Output is correct |
13 |
Correct |
1 ms |
1628 KB |
Output is correct |
14 |
Correct |
2 ms |
2160 KB |
Output is correct |
15 |
Correct |
1 ms |
1880 KB |
Output is correct |
16 |
Correct |
2 ms |
2136 KB |
Output is correct |
17 |
Correct |
1 ms |
1628 KB |
Output is correct |
18 |
Correct |
2 ms |
2168 KB |
Output is correct |
19 |
Correct |
2 ms |
1880 KB |
Output is correct |
20 |
Correct |
2 ms |
1884 KB |
Output is correct |
21 |
Correct |
2 ms |
1884 KB |
Output is correct |
22 |
Correct |
2 ms |
1880 KB |
Output is correct |
23 |
Correct |
3 ms |
2136 KB |
Output is correct |
24 |
Correct |
1 ms |
1884 KB |
Output is correct |
25 |
Correct |
3 ms |
2396 KB |
Output is correct |
26 |
Correct |
3 ms |
2136 KB |
Output is correct |
27 |
Correct |
3 ms |
2396 KB |
Output is correct |
28 |
Correct |
3 ms |
2144 KB |
Output is correct |
29 |
Correct |
3 ms |
2396 KB |
Output is correct |
30 |
Correct |
3 ms |
2140 KB |
Output is correct |
31 |
Correct |
3 ms |
2140 KB |
Output is correct |
32 |
Correct |
3 ms |
2140 KB |
Output is correct |
33 |
Correct |
4 ms |
2140 KB |
Output is correct |
34 |
Correct |
3 ms |
2140 KB |
Output is correct |
35 |
Correct |
2 ms |
1884 KB |
Output is correct |
36 |
Correct |
3 ms |
1900 KB |
Output is correct |
37 |
Correct |
2 ms |
1884 KB |
Output is correct |
38 |
Correct |
1 ms |
1628 KB |
Output is correct |
39 |
Correct |
2 ms |
1628 KB |
Output is correct |
40 |
Correct |
4 ms |
2396 KB |
Output is correct |
41 |
Correct |
2 ms |
1628 KB |
Output is correct |
42 |
Correct |
4 ms |
2392 KB |
Output is correct |
43 |
Correct |
4 ms |
2392 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2396 KB |
Output is correct |
2 |
Correct |
1 ms |
1628 KB |
Output is correct |
3 |
Correct |
1 ms |
1628 KB |
Output is correct |
4 |
Correct |
1 ms |
1628 KB |
Output is correct |
5 |
Correct |
1 ms |
1624 KB |
Output is correct |
6 |
Correct |
1 ms |
1628 KB |
Output is correct |
7 |
Correct |
2 ms |
1628 KB |
Output is correct |
8 |
Correct |
1 ms |
1628 KB |
Output is correct |
9 |
Correct |
2 ms |
1628 KB |
Output is correct |
10 |
Correct |
1 ms |
1628 KB |
Output is correct |
11 |
Runtime error |
2029 ms |
524288 KB |
Execution killed with signal 9 |
12 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
1880 KB |
Output is correct |
2 |
Correct |
1 ms |
1624 KB |
Output is correct |
3 |
Correct |
3 ms |
2140 KB |
Output is correct |
4 |
Correct |
2 ms |
2140 KB |
Output is correct |
5 |
Correct |
3 ms |
2140 KB |
Output is correct |
6 |
Correct |
2 ms |
2140 KB |
Output is correct |
7 |
Correct |
2 ms |
2140 KB |
Output is correct |
8 |
Correct |
1 ms |
2136 KB |
Output is correct |
9 |
Correct |
1 ms |
1628 KB |
Output is correct |
10 |
Correct |
1 ms |
1904 KB |
Output is correct |
11 |
Correct |
3 ms |
2136 KB |
Output is correct |
12 |
Correct |
2 ms |
2140 KB |
Output is correct |
13 |
Correct |
1 ms |
1628 KB |
Output is correct |
14 |
Correct |
2 ms |
2160 KB |
Output is correct |
15 |
Correct |
1 ms |
1880 KB |
Output is correct |
16 |
Correct |
2 ms |
2136 KB |
Output is correct |
17 |
Correct |
1 ms |
1628 KB |
Output is correct |
18 |
Correct |
2 ms |
2168 KB |
Output is correct |
19 |
Correct |
2 ms |
1880 KB |
Output is correct |
20 |
Correct |
2 ms |
1884 KB |
Output is correct |
21 |
Correct |
2 ms |
1884 KB |
Output is correct |
22 |
Correct |
2 ms |
1880 KB |
Output is correct |
23 |
Correct |
3 ms |
2136 KB |
Output is correct |
24 |
Correct |
1 ms |
1884 KB |
Output is correct |
25 |
Correct |
3 ms |
2396 KB |
Output is correct |
26 |
Correct |
3 ms |
2136 KB |
Output is correct |
27 |
Correct |
3 ms |
2396 KB |
Output is correct |
28 |
Correct |
3 ms |
2144 KB |
Output is correct |
29 |
Correct |
3 ms |
2396 KB |
Output is correct |
30 |
Correct |
3 ms |
2140 KB |
Output is correct |
31 |
Correct |
3 ms |
2140 KB |
Output is correct |
32 |
Correct |
3 ms |
2140 KB |
Output is correct |
33 |
Correct |
4 ms |
2140 KB |
Output is correct |
34 |
Correct |
3 ms |
2140 KB |
Output is correct |
35 |
Correct |
2 ms |
1884 KB |
Output is correct |
36 |
Correct |
3 ms |
1900 KB |
Output is correct |
37 |
Correct |
2 ms |
1884 KB |
Output is correct |
38 |
Correct |
1 ms |
1628 KB |
Output is correct |
39 |
Correct |
2 ms |
1628 KB |
Output is correct |
40 |
Correct |
4 ms |
2396 KB |
Output is correct |
41 |
Correct |
2 ms |
1628 KB |
Output is correct |
42 |
Correct |
4 ms |
2392 KB |
Output is correct |
43 |
Correct |
4 ms |
2392 KB |
Output is correct |
44 |
Correct |
704 ms |
34092 KB |
Output is correct |
45 |
Correct |
1 ms |
1628 KB |
Output is correct |
46 |
Runtime error |
2382 ms |
524288 KB |
Execution killed with signal 9 |
47 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
1880 KB |
Output is correct |
2 |
Correct |
1 ms |
1624 KB |
Output is correct |
3 |
Correct |
3 ms |
2140 KB |
Output is correct |
4 |
Correct |
2 ms |
2140 KB |
Output is correct |
5 |
Correct |
3 ms |
2140 KB |
Output is correct |
6 |
Correct |
2 ms |
2140 KB |
Output is correct |
7 |
Correct |
2 ms |
2140 KB |
Output is correct |
8 |
Correct |
1 ms |
2136 KB |
Output is correct |
9 |
Correct |
1 ms |
1628 KB |
Output is correct |
10 |
Correct |
1 ms |
1904 KB |
Output is correct |
11 |
Correct |
3 ms |
2136 KB |
Output is correct |
12 |
Correct |
2 ms |
2140 KB |
Output is correct |
13 |
Correct |
1 ms |
1628 KB |
Output is correct |
14 |
Correct |
2 ms |
2160 KB |
Output is correct |
15 |
Correct |
1 ms |
1880 KB |
Output is correct |
16 |
Correct |
2 ms |
2136 KB |
Output is correct |
17 |
Correct |
1 ms |
1628 KB |
Output is correct |
18 |
Correct |
2 ms |
2168 KB |
Output is correct |
19 |
Correct |
2 ms |
1880 KB |
Output is correct |
20 |
Correct |
2 ms |
1884 KB |
Output is correct |
21 |
Correct |
2 ms |
1884 KB |
Output is correct |
22 |
Correct |
2 ms |
1880 KB |
Output is correct |
23 |
Correct |
3 ms |
2136 KB |
Output is correct |
24 |
Correct |
1 ms |
1884 KB |
Output is correct |
25 |
Correct |
3 ms |
2396 KB |
Output is correct |
26 |
Correct |
3 ms |
2136 KB |
Output is correct |
27 |
Correct |
3 ms |
2396 KB |
Output is correct |
28 |
Correct |
3 ms |
2144 KB |
Output is correct |
29 |
Correct |
3 ms |
2396 KB |
Output is correct |
30 |
Correct |
3 ms |
2140 KB |
Output is correct |
31 |
Correct |
3 ms |
2140 KB |
Output is correct |
32 |
Correct |
3 ms |
2140 KB |
Output is correct |
33 |
Correct |
4 ms |
2140 KB |
Output is correct |
34 |
Correct |
3 ms |
2140 KB |
Output is correct |
35 |
Correct |
2 ms |
1884 KB |
Output is correct |
36 |
Correct |
3 ms |
1900 KB |
Output is correct |
37 |
Correct |
2 ms |
1884 KB |
Output is correct |
38 |
Correct |
1 ms |
1628 KB |
Output is correct |
39 |
Correct |
2 ms |
1628 KB |
Output is correct |
40 |
Correct |
4 ms |
2396 KB |
Output is correct |
41 |
Correct |
2 ms |
1628 KB |
Output is correct |
42 |
Correct |
4 ms |
2392 KB |
Output is correct |
43 |
Correct |
4 ms |
2392 KB |
Output is correct |
44 |
Correct |
1 ms |
1624 KB |
Output is correct |
45 |
Runtime error |
2191 ms |
524288 KB |
Execution killed with signal 9 |
46 |
Halted |
0 ms |
0 KB |
- |