제출 #1001441

#제출 시각아이디문제언어결과실행 시간메모리
1001441vjudge3Bosses (BOI16_bosses)C++17
0 / 100
0 ms604 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; vector<int> g[5005]; ll root (int s) { vector<ll> dist (5005, 1e18); dist[s] = 1; ll res = 0; queue<ll> q; q.push(s); while (!q.empty()) { int u = q.front(); res += dist[u]; q.pop(); for (auto& v : g[u]) if (dist[u] + 1 < dist[v]) { dist[v] = dist[u]+1; q.push(v); } } return res; } int main () { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; for (int i = 1; i <= n; i++) { int c; cin >> c; while (c--) { int u; cin >> u; g[u].push_back(i); } } ll ans = 1e18; for (int i = 1; i <= n; i++) ans = min(ans, root(i)); cout << ans << '\n'; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...