제출 #894714

#제출 시각아이디문제언어결과실행 시간메모리
894714PekibanBosses (BOI16_bosses)C++17
100 / 100
451 ms788 KiB
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); int n; cin >> n; vector<int> v[n]; for (int i = 0; i < n; ++i) { int k; cin >> k; while (k--) { int u; cin >> u; u--; v[u].push_back(i); } } bitset<5000> bs; bs.reset(); long long ans = 1e9; int dep[n]; for (int i = 0; i < n; ++i) { bs.reset(); queue<int> q; q.push(i); dep[i] = 1; long long sum = 1; bs[i] = 1; while (!q.empty()) { int s = q.front(); q.pop(); for (auto u : v[s]) { if (bs[u] == 0) { bs[u] = 1; q.push(u); dep[u] = dep[s] + 1; sum += dep[u]; } } } for (int i = 0; i < n; ++i) { if (bs[i] == 0) { sum += 1e9; } } ans = min(ans, sum); } cout << ans << '\n'; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...