Submission #1044133

#TimeUsernameProblemLanguageResultExecution timeMemory
1044133inkvizytorBosses (BOI16_bosses)C++17
100 / 100
430 ms796 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); for (int i = 1; i < n+1; i++) { int k; cin >> k; for (int j = 0; j < k; j++) { int x; cin >> x; g[x].push_back(i); } } int mini = 1000000000; for (int i = 1; i < n+1; i++) { vector<bool> odw (n+1, 0); vector<int> d (n+1, 0); odw[i] = 1; d[i] = 1; queue<int> q; q.push(i); int score = 1; 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; score += d[u]; q.push(u); } } } for (int i = 1; i < n+1; i++) { if (!odw[i]) { score = 1000000000; } } mini = min(mini, score); } cout << mini << '\n'; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...