제출 #950419

#제출 시각아이디문제언어결과실행 시간메모리
950419LucaIlieBosses (BOI16_bosses)C++17
100 / 100
401 ms772 KiB
#include <bits/stdc++.h> using namespace std; const int MAX_N = 5000; vector<int> employees[MAX_N + 1]; bool vis[MAX_N + 1]; int depth[MAX_N + 1]; int main() { int n; cin >> n; for ( int u = 1; u <= n; u++ ) { int k; cin >> k; for ( int i = 0; i < k; i++ ) { int v; cin >> v; employees[v].push_back( u ); } } int minCost = n * n; for ( int s = 1; s <= n; s++ ) { queue<int> q; for ( int v = 1; v <= n; v++ ) { depth[v] = 0; vis[v] = false; } int steps = 0; vis[s] = true; depth[s] = 1; q.push( s ); while ( !q.empty() ) { int u = q.front(); q.pop(); steps++; for ( int v: employees[u] ) { if ( !vis[v] ) { vis[v] = true; depth[v] = depth[u] + 1; q.push( v ); } } } if ( steps < n ) continue; int cost = 0; for ( int v = 1; v <= n; v++ ) cost += depth[v]; minCost = min( minCost, cost ); } cout << minCost; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...