Submission #733485

#TimeUsernameProblemLanguageResultExecution timeMemory
733485JellyTheOctopusBosses (BOI16_bosses)C++17
0 / 100
0 ms340 KiB
#include <bits/stdc++.h> using namespace std; int N; bool adjMat[5001][5001]; long long bfs(int root) { vector<bool> seen(N+1); queue<pair<int, long long>> q; // node, depth q.push({root, 1}); // starting depth at one seen[root] = true; long long ans = 0; while (!q.empty()) { pair<int, long long> cur = q.front(); int u = cur.first; long long depth = cur.second; q.pop(); ans += depth; for (int v = 1; v <= N; v++) { if (adjMat[u][v] && !seen[v]) { q.push({v, depth+1}); seen[v] = true; } } } return ans; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cin >> N; for (int v = 1; v <= N; v++) { int k; cin >> k; for (int i = 0; i < k; i++) { int u; cin >> u; adjMat[u][v] = true; } } long long ans = LLONG_MAX; for (int i = 1; i <= N; i++) { ans = min(ans, bfs(i)); } cout << ans << "\n"; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...