This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
//https://oj.uz/problem/view/BOI16_bosses
#include<bits/stdc++.h>
const int N = 5005;
using namespace std;
vector <int> adj[N];
int n, d[N], ans = N*N;
void bfs(int u){
int sum = 0, cnt = 0;
for (int i = 1; i <= n; i++) d[i] = 0;
queue <int> mq;
mq.push(u); d[u] = 1;
while(mq.size()){
int u = mq.front(); mq.pop();
sum += d[u]; cnt++;
for (auto v : adj[u]){
if (!d[v]){
d[v] = d[u] + 1;
mq.push(v);
}
}
}
if (cnt == n) ans = min(ans, sum);
}
int main(){
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
cin >> n;
for (int i = 1; i <= n; i++) {
int k, x; cin >> k;
while (k--){
cin >> x;
adj[x].push_back(i);
}
}
for (int i = 1; i <= n; i++) bfs(i);
cout << ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |