Submission #208083

#TimeUsernameProblemLanguageResultExecution timeMemory
208083BlerarghBosses (BOI16_bosses)C++17
67 / 100
1590 ms1020 KiB
#include "bits/stdc++.h" using namespace std; #define int long long bool vis[5005]; int preorder[5005],nex; int cur,nodes; vector<int> children[5005],children2[5005]; void dfs(int x){//returns salary of employee x... preorder[x]=nex++; for(int i=0;i<children2[x].size();i++)dfs(children2[x][i]); cur+=nex-preorder[x]; } int32_t main() { ios_base::sync_with_stdio(false);cin.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++){vis[i]=0;children2[i].clear();} bfs.push(x);vis[x]=1; nodes=0; while(!bfs.empty()){ nodes++; a=bfs.front(); bfs.pop(); for(int i=0;i<children[a].size();i++){ if(!vis[children[a][i]]){ vis[children[a][i]]=true; bfs.emplace(children[a][i]); children2[a].push_back(children[a][i]); } } } if(nodes!=n)continue; cur=0; nex=1; dfs(x); ans=min(ans,cur); } cout<<ans<<'\n'; return 0; }

Compilation message (stderr)

bosses.cpp: In function 'void dfs(long long int)':
bosses.cpp:13:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int i=0;i<children2[x].size();i++)dfs(children2[x][i]);
               ~^~~~~~~~~~~~~~~~~~~~
bosses.cpp: In function 'int32_t main()':
bosses.cpp:39:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(int i=0;i<children[a].size();i++){
                     ~^~~~~~~~~~~~~~~~~~~
bosses.cpp:21:10: warning: unused variable 'broke' [-Wunused-variable]
     bool broke;
          ^~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...