제출 #733490

#제출 시각아이디문제언어결과실행 시간메모리
733490JellyTheOctopusBosses (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 int ans = 0; while (!q.empty()) { pair<int, int> cur = q.front(); int u = cur.first; int depth = cur.second; q.pop(); if (!seen[u]) { seen[u] = true; ans += depth; for (auto v: adjList[u]) { if (!seen[v]) { q.push({v, depth+1}); } } } } 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 = 1000; 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...