This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
#define fastio ios::sync_with_stdio(false), cin.tie(0)
#pragma GCC optimize("Ofast")
#define pb push_back
#define eb emplace_back
#define f first
#define s second
#define int long long
const int maxn = 2e5 + 5;
vector<int> adj[maxn], nadj[maxn];
int deg[maxn];
signed main(void){
fastio;
int n, k;
cin>>n>>k;
for(int i = 0; i < n; i++){
int d;
cin>>d;
deg[i] = d;
for(int j = 0; j < d; j++){
int x;
cin>>x;
adj[i].pb(x);
}
}
for(int i = 0; i < n; i++){
for(auto x : adj[i]){
if(deg[i] < deg[x]) nadj[i].pb(x);
else if(deg[i] == deg[x] && i < x) nadj[i].pb(x);
}
}
int ans = 0;
auto dfs = [&](auto self, int pos, int ttl, vector<int>& cnt) -> void{
ans = max(ans, ttl);
for(auto x : nadj[pos]) cnt[x]++;
for(auto x : nadj[pos]){
if(cnt[x] >= ttl){
self(self, x, ttl + 1, cnt);
}
}
for(auto x : nadj[pos]) cnt[x] --;
};
vector<int> cnt(n);
for(int i = 0; i < n; i++){
dfs(dfs, i, 1, cnt);
}
cout<<ans<<"\n";
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |