제출 #207820

#제출 시각아이디문제언어결과실행 시간메모리
207820bensonlzlBosses (BOI16_bosses)C++14
100 / 100
758 ms888 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; ll N, K, X, dist[5005]; vector<ll> employ[5005]; ll bfs(int x){ ll sum = 0; for (int i = 1; i <= N; ++i) dist[i] = 1e9; dist[x] = 0; queue<int> q; q.push(x); while (!q.empty()){ int v = q.front(); q.pop(); for (auto it : employ[v]){ if (dist[it] > dist[v] + 1){ dist[it] = dist[v] + 1; q.push(it); } } } for (int i = 1; i <= N; ++i){ sum += dist[i]; } return sum + N; } int main(){ ios_base::sync_with_stdio(false); cin.tie(0); cin >> N; for (int i = 1; i <= N; ++i){ cin >> K; for (int j = 1; j <= K; ++j){ cin >> X; employ[X].push_back(i); } } ll mini = 1e9; for (int i = 1; i <= N; ++i){ mini = min(mini,bfs(i)); } cout << mini << '\n'; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...