Submission #971326

#TimeUsernameProblemLanguageResultExecution timeMemory
971326detectivebowonBosses (BOI16_bosses)C++17
100 / 100
579 ms796 KiB
#include <bits/stdc++.h> #define ep emplace #define epb emplace_back #define int long long using namespace std; int n, va[5007], mn = LLONG_MAX, value; vector<int> adj[5007]; bool visited[5007]; queue<pair<int,int>> q; signed main() { cin >> n; for (int i = 1; i <= n; i++) { int num; cin >> num; while (num--) { int v; cin >> v; adj[v].epb(i); } } for (int i = 1; i <= n; i++) { q.push({1, i}); int sum = 0, cnt = 0; memset(visited, 0, sizeof(visited)); while (!q.empty()) { int u = q.front().second, cost = q.front().first; q.pop(); if (visited[u]) continue; visited[u] = true; sum += cost; cnt++; for (auto v : adj[u]) if (!visited[v]) q.push({cost + 1, v}); } if (cnt == n) mn = min(mn, sum); } cout << mn; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...