제출 #970867

#제출 시각아이디문제언어결과실행 시간메모리
970867starchanBosses (BOI16_bosses)C++17
100 / 100
435 ms820 KiB
#include<bits/stdc++.h> using namespace std; #define int unsigned long long #define in pair<int, int> #define f first #define s second #define pb push_back #define pob pop_back #define INF (int)1e18 #define MX (int)5000+5 #define fast() ios_base::sync_with_stdio(false); cin.tie(NULL) int n; vector<int> poss_child[MX]; int solve(int u) { queue<int> bfsq; vector<int> dist(n+1, INF); bfsq.push(u); dist[u] = 1; int ans = 0; while(bfsq.size()) { int v = bfsq.front(); bfsq.pop(); ans+=dist[v]; for(int k: poss_child[v]) { if(dist[k] != INF) continue; dist[k] = dist[v]+1; bfsq.push(k); } } for(int i = 1; i <= n; i++) { if(dist[i] == INF) return INF; } return ans; } signed main() { fast(); cin >> n; for(int i = 1; i <= n; i++) { int k; cin >> k; while(k--) { int u; cin >> u; poss_child[u].pb(i); } } int ans = INF; for(int i = 1; i <= n; i++) ans = min(ans, 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...