제출 #1112159

#제출 시각아이디문제언어결과실행 시간메모리
1112159PagodePaivaBosses (BOI16_bosses)C++17
100 / 100
414 ms720 KiB
#include<bits/stdc++.h> using namespace std; const int N = 5010; vector <int> g[N]; int mark[N]; int main(){ int n; cin >> n; for(int i = 1;i <= n;i++){ int x; cin >> x; for(int j = 0;j < x;j++){ int t; cin >> t; g[t].push_back(i); } } int res = 1e9; for(int v = 1;v <= n;v++){ for(int i = 1;i <= n;i++){ mark[i] = 0; } queue <int> q; mark[v] = 1; q.push(v); int sum = 0; while(!q.empty()){ int t = q.front(); q.pop(); sum += mark[t]; for(auto x : g[t]){ if(mark[x] > 0) continue; mark[x] = mark[t]+1; q.push(x); } } bool aux = true; for(int i = 1;i <= n;i++){ if(mark[i] == 0) aux = false; } if(aux) res = min(res, sum); } cout << res << '\n'; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...