# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
197122 | dantoh000 | Bosses (BOI16_bosses) | C++14 | 988 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> adjlist[5005];
int d[5005];
queue<int> q;
int main(){
int n;
scanf("%d",&n);
for (int i = 1; i <= n; i++){
int k;
scanf("%d",&k);
while (k--){
int x;
scanf("%d",&x);
adjlist[x].push_back(i);
}
}
int ans = 1000000000;
for (int i = 1; i <= n; i++){
memset(d,-1,sizeof(d));
d[i] = 0;
q.push(i);
while (q.size()){
int u = q.front(); q.pop();
for (auto v : adjlist[u]){
if (d[v] == -1){
d[v] = d[u]+1;
q.push(v);
}
}
}
int sum = 0;
for (int i = 1; i <= n; i++){
if (d[i] == -1) goto done;
//printf("%d ",d[i]);
sum += d[i]+1;
}
//printf("\n");
ans = min(ans,sum);
done:;
}
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... |