Submission #733487

#TimeUsernameProblemLanguageResultExecution timeMemory
733487JellyTheOctopusBosses (BOI16_bosses)C++17
0 / 100
0 ms340 KiB
#include <bits/stdc++.h> using namespace std; int N; vector<int> adjList[5001]; int bfs(int root) { vector<bool> seen(N+1); queue<pair<int, int>> q; // node, depth q.push({root, 1}); // starting depth at one seen[root] = true; int ans = 0; while (!q.empty()) { pair<int, int> cur = q.front(); int u = cur.first; int depth = cur.second; q.pop(); ans += depth; for (auto v: adjList[u]) { if (!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; adjList[u].push_back(v); } } int ans = INT_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...