Submission #520690

#TimeUsernameProblemLanguageResultExecution timeMemory
520690Alex_tz307Bosses (BOI16_bosses)C++17
100 / 100
729 ms588 KiB
#include <bits/stdc++.h> #define INF 0x3f3f3f3f using namespace std; void minSelf(int &x, int y) { if (y < x) { x = y; } } void testCase() { int n; cin >> n; vector<vector<int>> g(n + 1); for (int v = 1; v <= n; ++v) { int k; cin >> k; for (int i = 0; i < k; ++i) { int u; cin >> u; g[u].emplace_back(v); } } int ans = INF; for (int root = 1; root <= n; ++root) { vector<int> level(n + 1); level[root] = 1; queue<int> q; q.emplace(root); while (!q.empty()) { int u = q.front(); q.pop(); for (int v : g[u]) { if (!level[v]) { level[v] = level[u] + 1; q.emplace(v); } } } if (*min_element(level.begin() + 1, level.end()) != 0) { minSelf(ans, accumulate(level.begin() + 1, level.end(), 0)); } } cout << ans << '\n'; } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); int tests = 1; for (int tc = 0; tc < tests; ++tc) { testCase(); } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...