Submission #790052

#TimeUsernameProblemLanguageResultExecution timeMemory
790052tch1cherinBosses (BOI16_bosses)C++17
100 / 100
418 ms660 KiB
#include <bits/stdc++.h> using namespace std; const int MAX_N = 5005; vector<int> G[MAX_N]; int main() { cin.tie(nullptr)->sync_with_stdio(false); int N; cin >> N; for (int i = 0; i < N; i++) { int k; cin >> k; for (int j = 0; j < k; j++) { int v; cin >> v; v--; G[v].push_back(i); } } int ans = INT_MAX; for (int i = 0; i < N; i++) { vector<int> depth(N); queue<int> q; q.push(i); depth[i] = 1; while (!q.empty()) { int u = q.front(); q.pop(); for (int v : G[u]) { if (!depth[v]) { depth[v] = depth[u] + 1; q.push(v); } } } if (!count(depth.begin(), depth.end(), 0)) { ans = min(ans, accumulate(depth.begin(), depth.end(), 0)); } } cout << ans << "\n"; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...