제출 #946295

#제출 시각아이디문제언어결과실행 시간메모리
946295parsadox2Bosses (BOI16_bosses)C++17
100 / 100
392 ms848 KiB
#include <bits/stdc++.h> using namespace std; const int N = 5e3 + 10; int n , dis[N] , ans; vector <int> adj[N]; bool marked[N]; void Solve(int star) { for(int i = 1 ; i <= n ; i++) marked[i] = false; queue <int> q; marked[star] = true; dis[star] = 1; q.push(star); int cnt = n , tmp = 0; while(!q.empty()) { int v = q.front(); q.pop(); tmp += dis[v]; cnt--; for(auto u : adj[v]) if(!marked[u]) { marked[u] = true; q.push(u); dis[u] = dis[v] + 1; } } if(cnt == 0) ans = min(ans , tmp); } signed main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n; for(int i = 1 ; i <= n ; i++) { int k; cin >> k; while(k--) { int x; cin >> x; adj[x].push_back(i); } } ans = N * N; for(int i = 1 ; i <= n ; i++) Solve(i); cout << ans << '\n'; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...