제출 #282831

#제출 시각아이디문제언어결과실행 시간메모리
282831wutwereBosses (BOI16_bosses)C++17
100 / 100
982 ms760 KiB
#include <bits/stdc++.h> using namespace std; vector<int> boss[5001]; int main() { ios::sync_with_stdio(0); cin.tie(0); int n; cin >> n; for (int i = 1; i <= n; i++) { int k; cin >> k; for (int j = 0; j < k; j++) { int b; cin >> b; boss[b].push_back(i); } } int ans = 1e9; for (int i = 1; i <= n; i++) { vector<bool> vis(n + 1); int nodes = 0, sum = 0; queue<pair<int, int>> q; q.push({i, 1}); while (!q.empty()) { int cur = q.front().first, dep = q.front().second; q.pop(); if (vis[cur]) continue; vis[cur] = true; nodes++; sum += dep; for (int b : boss[cur]) { q.push({b, dep + 1}); } } if (nodes == n) { // cerr << "D " << i << ' ' << sum << '\n'; ans = min(ans, sum); } } cout << ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...