# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
235458 | anonymous | Bosses (BOI16_bosses) | C++14 | 760 ms | 760 KiB |
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 <iostream>
#include <queue>
#include <vector>
#define MAXN 5005
using namespace std;
int N, Ans=1<<30, Val, ki, dist[MAXN];
vector <int> adj[MAXN];
queue <int> Q;
int main() {
//freopen("bossin.txt","r",stdin);
scanf("%d",&N);
for (int i=1; i<=N; i++) {
scanf("%d", &ki);
for (int j=0; j<ki; j++) {
int ai;
scanf("%d",&ai);
adj[ai].push_back(i);
}
}
for (int i=1; i<=N; i++) {
for (int j=1; j<=N; j++) {
dist[j] = i == j ? 1 : 1<<30;
}
Val = 0;
Q.push(i);
int vis = 0;
while (Q.size()) {
int u = Q.front();
vis++;
Q.pop();
Val += dist[u];
for (int v: adj[u]) {
if (dist[v] > dist[u] + 1) {
dist[v] = dist[u] + 1;
Q.push(v);
}
}
}
if (vis == N) {Ans = min(Ans, Val);}
}
printf("%d",Ans);
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |