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;
int dist[5005];
vector<int> children[5005];
int32_t main() {
//ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
queue<int> bfs;
int n,k,a,maxi,ans=INT_MAX,cur;
cin>>n;
for(int x=1;x<=n;x++){
cin>>k;
while(k--){
cin>>a;
children[a].push_back(x);
}
}
for(int x=1;x<=n;x++){
for(int i=1;i<=n;i++)dist[i]=INT_MAX;
bfs.push(x);dist[x]=cur=maxi=0;
while(!bfs.empty()){
a=bfs.front();
bfs.pop();
for(int i=0;i<children[a].size();i++){
if(dist[children[a][i]]==INT_MAX){
dist[children[a][i]]=dist[a]+1;
maxi=max(maxi,dist[a]+1);
bfs.push(children[a][i]);
}
}
}
maxi++;
for(int i=1;i<=n;i++){
cur+=maxi-dist[i];
}
ans=min(ans,cur);
}
cout<<ans<<'\n';
return 0;
}
Compilation message (stderr)
bosses.cpp: In function 'int32_t main()':
bosses.cpp:26:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0;i<children[a].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... |