Submission #563902

#TimeUsernameProblemLanguageResultExecution timeMemory
563902Waratpp123Bosses (BOI16_bosses)C++14
100 / 100
621 ms680 KiB
#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)

bosses.cpp: In function 'int main()':
bosses.cpp:8:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    8 |     scanf("%lld",&n);
      |     ~~~~~^~~~~~~~~~~
bosses.cpp:10:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   10 |         scanf("%lld",&m);
      |         ~~~~~^~~~~~~~~~~
bosses.cpp:12:18: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   12 |             scanf("%lld",&j);
      |             ~~~~~^~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...