Submission #924997

#TimeUsernameProblemLanguageResultExecution timeMemory
924997NintsiChkhaidzeBosses (BOI16_bosses)C++17
100 / 100
438 ms872 KiB
#include <bits/stdc++.h> #define ll long long #define s second #define f first #define pb push_back #define pii pair <int,int> #define left (h<<1),l,(l + r)/2 #define right ((h<<1)|1),(l + r)/2 + 1,r #define int ll using namespace std; const int N = 5000 + 3; int vis[N],dep[N],cnt[N]; vector <int> v[N]; signed main(){ ios_base::sync_with_stdio(0),cin.tie(NULL),cout.tie(NULL); int n; cin>>n; for (int i = 1; i <= n; i++){ int k; cin>>k; for (int j= 1; j <= k; j++){ int x; cin>>x; v[x].pb(i); } } int ans = 1e18; for (int root = 1; root <= n; root++){ for (int i = 1;i <= n; i++) dep[i] = 0,cnt[i] = 0; queue <int> q; q.push(root); dep[root] = 1; int c=0; while(q.size()){ int x = q.front(); q.pop(); ++c; for (int to: v[x]){ if (!dep[to]) { dep[to] = dep[x] + 1; q.push(to); } } } if (c < n) continue; for(int i=1;i<=n;i++) cnt[dep[i]]++; int sum = n,cur = n; for (int i = 1; i <= n; i++){ cur -= cnt[i]; sum += cur; } ans=min(ans,sum); } cout<<ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...