Submission #338123

#TimeUsernameProblemLanguageResultExecution timeMemory
338123MilosMilutinovicBosses (BOI16_bosses)C++14
100 / 100
1127 ms876 KiB
#include <bits/stdc++.h> using namespace std; #define pb push_back const int N=5050; vector<int> E[N]; int n; int BFS(int u){ bool was[n+1]; int dist[n+1],cnt[n+1],dp[n+1]; for(int i=0;i<=n;i++)was[i]=false,dist[i]=N*2,cnt[i]=0,dp[i]=0; deque<int> q; q.pb(u); dist[u]=0,was[u]=1; while(!q.empty()){ int x=q[0]; for(int c:E[x]){ dist[c]=min(dist[c],dist[x]+1); if(!was[c]){ was[c]=1; q.pb(c); } } q.pop_front(); } for(int i=1;i<=n;i++){ if(dist[i]==2*N)return N*N*2; cnt[dist[i]]++; } for(int i=n-1;i>=0;i--)dp[i]=dp[i+1]+cnt[i]; int ans=0; for(int i=0;i<n;i++)ans+=dp[i]; return ans; } int main(){ scanf("%i",&n); for(int i=1;i<=n;i++){ int sz;scanf("%i",&sz); while(sz--){ int p;scanf("%i",&p); E[p].pb(i); } } int ans=N*N; for(int i=1;i<=n;i++){ int tmp=BFS(i); ans=min(ans,tmp); //printf("%i %i\n",i,tmp); } printf("%i",ans); return 0; }

Compilation message (stderr)

bosses.cpp: In function 'int main()':
bosses.cpp:35:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   35 |     scanf("%i",&n);
      |     ~~~~~^~~~~~~~~
bosses.cpp:37:21: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   37 |         int sz;scanf("%i",&sz);
      |                ~~~~~^~~~~~~~~~
bosses.cpp:39:24: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   39 |             int p;scanf("%i",&p);
      |                   ~~~~~^~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...