Submission #940433

#TimeUsernameProblemLanguageResultExecution timeMemory
940433phoenix0423Political Development (BOI17_politicaldevelopment)C++17
100 / 100
67 ms24524 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...