제출 #1091824

#제출 시각아이디문제언어결과실행 시간메모리
1091824vjudge1Bosses (BOI16_bosses)C++17
100 / 100
519 ms860 KiB
#include <bits/stdc++.h> #define int long long int using namespace std; const int maxn = 5010, inf = 1e18; int h[maxn], n, comp, tmp; vector<int> adj[maxn]; bool mark[maxn]; queue<int> q; void bfs(int source){ q.push(source); h[source] = 1; mark[source] = true; while(q.size()){ comp++; int v = q.front(); q.pop(); tmp += h[v]; for(auto u : adj[v]){ if(!mark[u]){ h[u] = h[v] + 1; mark[u] = true; q.push(u); } } } } int32_t main(){ ios::sync_with_stdio(0) ,cout.tie(0) ,cin.tie(0); cin >> n; for(int i =1 ; i<= n; i++){ int sz; cin >> sz; while(sz--){ int x; cin >> x; adj[x].push_back(i); } } int ans = inf; for(int i = 1; i <= n ; i++){ for(int i = 1 ; i<= n; i++){ mark[i] = 0; h[i] = 0; } comp = 0; tmp = 0; bfs(i); if(comp == n){ ans = min(ans ,tmp); } } cout << ans << endl; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...