Submission #208068

#TimeUsernameProblemLanguageResultExecution timeMemory
208068kai824Bosses (BOI16_bosses)C++17
67 / 100
1585 ms760 KiB
#include "bits/stdc++.h" using namespace std; bool vis[5005]; int dist[5005],cur; vector<int> children[5005]; int dfs(int x){//returns salary of employee x... vis[x]=true; int ans=1; for(int i=0;i<children[x].size();i++){ if(vis[children[x][i]])continue; if(dist[children[x][i]]!=dist[x]+1)continue; ans+=dfs(children[x][i]); } cur+=ans; return ans; } int32_t main() { ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); queue<int> bfs; int n,k,a,ans=INT_MAX; bool broke; 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;vis[i]=false;} bfs.push(x);dist[x]=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; bfs.push(children[a][i]); } } } broke=false; for(int i=1;i<=n;i++){ if(dist[i]==INT_MAX){ broke=true; break; } } if(broke)continue; cur=0; dfs(x); ans=min(ans,cur); } cout<<ans<<'\n'; return 0; }

Compilation message (stderr)

bosses.cpp: In function 'int dfs(int)':
bosses.cpp:11:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int i=0;i<children[x].size();i++){
               ~^~~~~~~~~~~~~~~~~~~
bosses.cpp: In function 'int32_t main()':
bosses.cpp:40:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(int i=0;i<children[a].size();i++){
                     ~^~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...