제출 #1112143

#제출 시각아이디문제언어결과실행 시간메모리
1112143ortsacBosses (BOI16_bosses)C++17
100 / 100
519 ms828 KiB
#include <bits/stdc++.h> using namespace std; #define int long long const int INF = 0x3f3f3f3f; const int MAXN = 5010; vector<int> adj[MAXN]; int32_t main() { int n; cin >> n; for (int i = 1; i <= n; i++) { int x; cin >> x; while (x--) { int a; cin >> a; adj[a].push_back(i); } } int ans = 0x3f3f3f3f3f3f3f3f; for (int i = 1; i <= n; i++) { vector<int> dist(n + 1, INF); vector<bool> mark(n + 1); dist[i] = 1; mark[i] = 1; queue<int> q; q.push(i); while (!q.empty()) { int v = q.front(); q.pop(); for (auto u : adj[v]) { if (mark[u]) continue; mark[u] = 1; dist[u] = dist[v] + 1; q.push(u); } } int sum = 0; for (int i = 1; i <= n; i++) sum += dist[i]; ans = min(ans, sum); } cout << ans << "\n"; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...