Submission #733491

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