Submission #164149

#TimeUsernameProblemLanguageResultExecution timeMemory
164149kostia244Bosses (BOI16_bosses)C++17
100 / 100
936 ms888 KiB
//#define _GLIBCXX_DEBUG #include<bits/stdc++.h> #define pb push_back using namespace std; using ll = long long; using vi = vector<ll>; using vvi = vector<vi>; int n, ans = 1e9, t = 0; vvi g; int d[5050], q[5050], fi, en; int go(int v) { memset(d, -1, sizeof d); fi = 0; en = 1; q[0] = v; d[v]=1; while(fi < en) { int u = q[fi++]; for(auto v : g[u]) { if(d[v]!=-1) continue; d[v] = d[u]+1; q[en++] = v; } } ll ans = 0; for(int i = 1; i <= n; i++) if(d[i]==-1) return 1e9; else ans += d[i]; return ans; } int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n; g.resize(n+1); for(int k, t, i = 1; i <= n; i++) { cin >> k; while(k--) cin >> t, g[t].pb(i); } for(int i = 1; i <= n; i++) { ans = min(ans, go(i)); } cout << ans << "\n"; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...