# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
563902 | Waratpp123 | Bosses (BOI16_bosses) | C++14 | 621 ms | 680 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<long long> g[5010];
long long dis[5010];
queue<long long> bfs;
int main(){
long long n,m,i,j,cnt=0,p,ans=1ll<<60,now;
scanf("%lld",&n);
for(i=1;i<=n;i++){
scanf("%lld",&m);
while(m--){
scanf("%lld",&j);
g[j].push_back(i);
}
}
for(i=1;i<=n;i++){
while(!bfs.empty()) bfs.pop();
memset(dis,127,sizeof dis);
cnt=0;
p=0;
dis[i]=1;
bfs.push(i);
while(!bfs.empty()){
now=bfs.front();
p+=dis[now];
cnt++;
bfs.pop();
for(auto x : g[now]){
if(dis[x]<=dis[now]+1) continue;
dis[x]=dis[now]+1;
bfs.push(x);
}
}
if(cnt!=n) continue;
ans=min(ans,p);
}
printf("%lld",ans);
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... |