Submission #171164

#TimeUsernameProblemLanguageResultExecution timeMemory
171164WLZBosses (BOI16_bosses)C++14
0 / 100
2 ms376 KiB
#include <bits/stdc++.h> using namespace std; const long long INF = (long long) 1e18; int n; vector< vector<int> > g; int main() { ios::sync_with_stdio(false); cin.tie(0); cin >> n; g.resize(n + 1); for (int i = 1; i <= n; i++) { int k; cin >> k; while (k--) { int p; cin >> p; g[p].push_back(i); } } long long ans = INF; for (int i = 1; i <= n; i++) { vector<int> d(n + 1, -1); d[i] = 1; priority_queue< pair<int, int>, vector< pair<int, int> >, greater< pair<int, int> > > pq; long long tmp = 1; for (auto& v : g[i]) { pq.push({1, v}); } while (!pq.empty()) { pair<int, int> cur = pq.top(); pq.pop(); if (d[cur.second] != -1) { continue; } d[cur.second] = cur.first + 1; tmp += (long long) d[cur.second]; for (auto& v : g[cur.second]) { if (d[v] == -1) { pq.push({d[cur.second], v}); } } } ans = min(ans, tmp); } cout << ans << '\n'; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...