Submission #727994

#TimeUsernameProblemLanguageResultExecution timeMemory
727994WonderfulWhaleBosses (BOI16_bosses)C++17
100 / 100
646 ms708 KiB
#include<bits/stdc++.h> using namespace std; #define int int64_t #define pb push_back #define st first #define nd second #define pii pair<int, int> #define all(x) (x).begin(), (x).end() #define sz(x) (int)(x).size() vector<int> G[5009]; bool vis[5009]; int d[5009]; int sum; int cnt; void bfs(int x) { queue<int> Q; Q.push(x); sum = cnt = 0; d[x] = 1; memset(vis, 0, sizeof(vis)); vis[x] = true; while(sz(Q)) { int y = Q.front(); Q.pop(); cnt++; sum += d[y]; for(int z:G[y]) { if(!vis[z]) { d[z] = d[y]+1; vis[z] = true; Q.push(z); } } } } int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n; cin >> n; for(int i=1;i<=n;i++) { int k; cin >> k; for(int j=0;j<k;j++) { int x; cin >> x; G[x].pb(i); } } int res = 1e18; for(int i=1;i<=n;i++) { bfs(i); if(cnt==n) res = min(res, sum); } cout << res << "\n"; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...