This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |