제출 #97087

#제출 시각아이디문제언어결과실행 시간메모리
97087dalgerokBosses (BOI16_bosses)C++14
100 / 100
597 ms760 KiB
#include<bits/stdc++.h> using namespace std; const int N = 5005, INF = 1e9; int n, d[N]; int ans = INF; vector < int > g[N]; inline void bfs(int rt){ for(int i = 1; i <= n; i++){ d[i] = INF; } d[rt] = 1; queue < int > q; q.push(rt); while(!q.empty()){ int v = q.front(); q.pop(); for(int to : g[v]){ if(d[to] > d[v] + 1){ d[to] = d[v] + 1; q.push(to); } } } int sum = 0; for(int i = 1; i <= n; i++){ if(d[i] == INF){ return; } sum += d[i]; } //cout << rt << " " << sum << "\n"; ans = min(ans, sum); } int main(){ ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); cin >> n; for(int i = 1; i <= n; i++){ int x, y; cin >> x; for(int j = 1; j <= x; j++){ cin >> y; g[y].push_back(i); } } for(int i = 1; i <= n; i++){ bfs(i); } cout << ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...