# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
159455 | a_player | Bosses (BOI16_bosses) | C++14 | 995 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> grafo[5001];
int val[5001];
bitset<5001> v;
int N;
int bfs(int in){
v.reset();
memset(val,0,sizeof(val));
int s=0;
queue<int> q;
q.push(in);
v[in]=1;
val[in]=1;
while(!q.empty()){
int co=q.front();
q.pop();
s+=val[co];
for(int i=0;i<grafo[co].size();i++){
if(!v[grafo[co][i]]){
val[grafo[co][i]]=val[co]+1;
v[grafo[co][i]]=1;
q.push(grafo[co][i]);
}
}
}
for(int i=0;i<N;i++)if(!v[i])return (int)1e9;
return s;
}
int main(){
cin>>N;
for(int i=0;i<N;i++){
int n;
cin>>n;
for(int j=0;j<n;j++){
int a;
cin>>a;
grafo[a-1].push_back(i);
}
}
int mini=bfs(0);
for(int i=1;i<N;i++){
mini=min(mini,bfs(i));
}
cout<<mini;
}
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... |