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 <iostream>
#include <vector>
#include <queue>
using namespace std;
int n;
vector<vector<int>> v;
vector<int> viz;
void curat(){
int i;
for(i=0;i<=n;i++) viz[i]=0;
}
bool vf(){
int i;
for(i=1;i<=n;i++){
if(!viz[i]) return 0;
}
return 1;
}
int main()
{
int i,j,k,min1,sum,nod,depth,a;
cin>>n;
viz.resize(n+1);v.resize(n+1);
for(i=1;i<=n;i++){
cin>>k;
for(j=0;j<k;j++){
cin>>a;
v[a].push_back(i);
}
}
min1=1e9;
for(j=1;j<=n;j++){
sum=1;
queue<pair<int,int>> s;
s.push({j,1});
curat();viz[j]=1;
while(!s.empty()){
nod=s.front().first;
depth=s.front().second+1;
s.pop();
for(i=0;i<v[nod].size();i++){
if(!viz[v[nod][i]]){
viz[v[nod][i]]=1;
sum+=depth;
s.push({v[nod][i],depth});
}
}
}
if(vf())
min1=min(sum,min1);
}
cout<<min1;
return 0;
}
Compilation message (stderr)
bosses.cpp: In function 'int main()':
bosses.cpp:45:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
45 | for(i=0;i<v[nod].size();i++){
| ~^~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |