Submission #1001460

#TimeUsernameProblemLanguageResultExecution timeMemory
1001460vjudge3Bosses (BOI16_bosses)C++17
100 / 100
601 ms812 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; vector<int> g[5005]; int n; ll root (int s) { vector<ll> dist (5005, 1e9); dist[s] = 1; ll res = 0; queue<ll> q; q.push(s); while (!q.empty()) { int u = q.front(); q.pop(); for (auto& v : g[u]) if (dist[u] + 1 < dist[v]) { dist[v] = dist[u]+1; q.push(v); } } for (int i = 1; i <= n; i++) res += dist[i]; return res; } int main () { ios::sync_with_stdio(false); cin.tie(0); cin >> n; for (int i = 1; i <= n; i++) { int c; cin >> c; while (c--) { int u; cin >> u; g[u].push_back(i); } } ll ans = 1e18; for (int i = 1; i <= n; i++) ans = min(ans, root(i)); cout << ans << '\n'; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...