제출 #166916

#제출 시각아이디문제언어결과실행 시간메모리
166916ZeljaBosses (BOI16_bosses)C++14
100 / 100
934 ms988 KiB
#include <bits/stdc++.h> using namespace std; int n,k,pom; vector<int> mat[5003]; int dist[5003]; queue<int> q; long long cnt[5003],res; int main() { ios_base::sync_with_stdio(false); cin.tie(0);cout.tie(0); cin >> n; for(int i = 1; i <= n; i++){ cin >> k; for(int j = 0; j < k; j++){ cin >> pom; mat[pom].push_back(i); } } for(int i = 1; i <= n; i++){ for(int j = 1; j <= n; j++) dist[j] = 9999999; dist[i] = 1; q.push(i); while(!q.empty()){ pom = q.front(); q.pop(); for(auto x: mat[pom]){ if(dist[x] != 9999999) continue; dist[x] = dist[pom] + 1; q.push(x); } } for(int j = 1; j <= n; j++){ cnt[i] += dist[j]; } } res = cnt[1]; for(int i = 2; i <= n; i++){ res = min(res,cnt[i]); } cout << res; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...