Submission #360163

#TimeUsernameProblemLanguageResultExecution timeMemory
360163PetyBosses (BOI16_bosses)C++14
100 / 100
695 ms768 KiB
#include <bits/stdc++.h> using namespace std; int n, ans, dist[5002], k, x; vector<int>G[5002]; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n; for (int i = 1; i <= n; i++) { cin >> k; while (k--) { cin >> x; G[x].push_back(i); } } ans = 1e9; for (int i = 1; i <= n; i++) { memset(dist, -1, sizeof(dist)); dist[i] = 1; queue<int>q; q.push(i); int cost = 0, count = 0; while (!q.empty()) { int x = q.front(); q.pop(); cost += dist[x]; count++; for (auto it : G[x]) if (dist[it] == -1) { dist[it] = dist[x] + 1; q.push(it); } } if (count == n) ans = min(ans, cost); } cout << ans; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...