# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
520121 | krit3379 | Bosses (BOI16_bosses) | C++17 | 712 ms | 708 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;
#define N 5005
long long cnt,sum,ans=1e18;
vector<int> g[N];
bitset<N> vis;
queue<pair<int,int>> q;
int main(){
int n,i,k,c,a,cou;
scanf("%d",&n);
for(i=1;i<=n;i++){
scanf("%d",&k);
while(k--)scanf("%d",&c),g[c].push_back(i);
}
for(i=1;i<=n;i++){
vis=0;
sum=cnt=0;
q.push({i,1});
vis[i]=true;
while(!q.empty()){
a=q.front().first;
cou=q.front().second;
q.pop();
cnt++;
sum+=cou;
for(auto x:g[a])if(!vis[x])vis[x]=true,q.push({x,cou+1});
}
if(cnt==n)ans=min(ans,sum);
}
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... |