제출 #1298179

#제출 시각아이디문제언어결과실행 시간메모리
1298179kawhietBosses (BOI16_bosses)C++20
0 / 100
1 ms1292 KiB
#include <bits/stdc++.h> using namespace std; #define int long long signed main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n; cin >> n; vector<vector<int>> a(n); for (int i = 0; i < n; i++) { int m; cin >> m; while (m--) { int k; cin >> k; k--; a[k].push_back(i); } } int ans = 1e18; for (int r = 0; r < n; r++) { vector<vector<int>> g(n); vector<int> d(n, -1); queue<int> q; q.push(r); d[r] = 1; vector<bool> vis(n); vis[r] = 1; while (!q.empty()) { int i = q.front(); q.pop(); vis[i] = 1; for (auto j : a[i]) { if (!vis[j]) { d[j] = d[i] + 1; vis[j] = 1; q.push(j); } } } int res = accumulate(d.begin(), d.end(), 0LL); ans = min(ans, res); } cout << ans << '\n'; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...