제출 #520691

#제출 시각아이디문제언어결과실행 시간메모리
520691Alex_tz307Bosses (BOI16_bosses)C++17
100 / 100
730 ms696 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())) { 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...