Submission #1092785

#TimeUsernameProblemLanguageResultExecution timeMemory
1092785juicyBosses (BOI16_bosses)C++17
100 / 100
519 ms780 KiB
#include <bits/stdc++.h> using namespace std; #ifdef LOCAL #include "debug.h" #else #define debug(...) 42 #endif int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n; cin >> n; vector<vector<int>> g(n); for (int i = 0; i < n; ++i) { int k; cin >> k; while (k--) { int j; cin >> j; --j; g[j].push_back(i); } } vector<int> d(n, -1); int res = 1e9; for (int r = 0; r < n; ++r) { fill(d.begin(), d.end(), -1); d[r] = 1; queue<int> q{{r}}; while (q.size()) { int u = q.front(); q.pop(); for (int v : g[u]) { if (d[v] == -1) { d[v] = d[u] + 1; q.push(v); } } } if (!count(d.begin(), d.end(), -1)) { res = min(res, accumulate(d.begin(), d.end(), 0)); } } cout << res; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...