# | TimeUTC-0 | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
253829 | ChrisT | Bosses (BOI16_bosses) | C++17 | 694 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<bits/stdc++.h>
using namespace std;
vector<int> canChild[5005];
int dist[5005];
int main () {
int n;
scanf ("%d",&n);
for (int i = 1; i <= n; i++) {
int k; scanf ("%d",&k);
while (k--) {
int a; scanf ("%d",&a); canChild[a].push_back(i);
}
}
int ret = INT_MAX;
for (int rt = 1; rt <= n; rt++) {
memset(dist,0x3f,sizeof dist);
queue<int> q;
q.push(rt); int sz = 0, ans = 0; dist[rt] = 1;
while (!q.empty()) {
int cur = q.front(); q.pop();
++sz; ans += dist[cur];
for (int i : canChild[cur]) if (dist[cur] + 1 < dist[i]) {
dist[i] = dist[cur] + 1;
q.push(i);
}
}
if (sz == n) ret = min(ret,ans);
}
printf ("%d\n",ret);
return 0;
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... |