제출 #171166

#제출 시각아이디문제언어결과실행 시간메모리
171166WLZBosses (BOI16_bosses)C++14
100 / 100
1057 ms924 KiB
#include <bits/stdc++.h> using namespace std; const long long INF = (long long) 1e18; int n; vector< vector<int> > g; int main() { ios::sync_with_stdio(false); cin.tie(0); cin >> n; g.resize(n + 1); for (int i = 1; i <= n; i++) { int k; cin >> k; while (k--) { int p; cin >> p; g[p].push_back(i); } } long long ans = INF; for (int i = 1; i <= n; i++) { vector<int> dist(n + 1, -1); dist[i] = 1; queue<int> q; q.push(i); while (!q.empty()) { int u = q.front(); q.pop(); for (auto& v : g[u]) { if (dist[v] == -1) { dist[v] = dist[u] + 1; q.push(v); } } } int pos = 1; long long tmp = 0; for (int j = 1; j <= n; j++) { if (dist[j] == -1) { pos = 0; break; } tmp += (long long) dist[j]; } if (pos) { ans = min(ans, tmp); } } cout << ans << '\n'; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...