Submission #1041906

#TimeUsernameProblemLanguageResultExecution timeMemory
1041906inkvizytorBosses (BOI16_bosses)C++17
0 / 100
0 ms348 KiB
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n; cin >> n; vector<vector<int>> g (n+1); int zer = 0; for (int i = 1; i < n+1; i++) { int k; cin >> k; if (k == 0) { zer = i; } for (int j = 0; j < k; j++) { int x; cin >> x; g[x].push_back(i); } } vector<bool> odw (n+1, 0); vector<int> d (n+1, 0); int score = 0, mini = 1000000000; for (int i = 1; i < n+1; i++) { odw[i] = 1; d[i] = 1; queue<int> q; q.push(i); while (!q.empty()) { int v = q.front(); q.pop(); for (int u : g[v]) { if (!odw[u]) { odw[u] = 1; d[u] = d[v]+1; q.push(u); } } } score = 0; for (int j = 1; j < n+1; j++) { score += d[j]; odw[j] = 0; } mini = min(mini, score); if (i == zer) { cout << score; return 0; } } cout << mini << '\n'; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...