Submission #877482

#TimeUsernameProblemLanguageResultExecution timeMemory
877482Beerus13Bosses (BOI16_bosses)C++14
0 / 100
0 ms604 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long const int N = 5e3 + 5; int n; vector<int> g[N]; ll dp[N]; ll bfs(int u) { queue<int> q; memset(dp, 0x3f, sizeof(dp)); dp[u] = 1; q.push(u); while(q.size()) { int s = q.front(); q.pop(); for(int t : g[s]) if(dp[t] > dp[s] + 1) { dp[t] = dp[s] + 1; q.push(t); } } ll res = 0; for(int i = 1; i <= n; ++i) res += dp[i]; return res; } int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n; for(int i = 1; i <= n; ++i) { int k, x; cin >> k; while(k--) { cin >> x; g[x].push_back(i); } } ll ans = 1e18; for(int i = 1; i <= n; ++i) ans = min(ans, bfs(i)); cout << ans << '\n'; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...