Submission #541246

#TimeUsernameProblemLanguageResultExecution timeMemory
541246Ahmad_HasanBirokracija (COCI18_birokracija)C++17
60 / 100
1089 ms14536 KiB
#include <bits/stdc++.h> using namespace std; vector<vector<int>>adj ; int n; vector<int>can; vector<int>ans; int o=0; int dfs(int m=0,int p=-1){ /** if(vis[m]==1||can[m]==1){ return 0; }*/ /**if(adj[m].size()==1&&m!=0){///leaf node can[m]=1; return 1; }*/ int mn=1e6; for(int i=0;i<adj[m].size();i++){ int nd=adj[m][i]; if(nd!=p&&!can[nd]){ mn=nd; break; } } if(mn==1e6){ can[m]=1; ans[m]+=1; return 1; } int ret=dfs(mn,m); ret++; ans[m]+=ret; return ret; } int main() { cin>>n; adj=vector<vector<int> >(n); can=ans=vector<int>(n); for(int i=2;i<=n;i++){ int u; cin>>u; adj[u-1].push_back(i-1); adj[i-1].push_back(u-1); } for(int i=0;i<n;i++){ dfs(); } for(int i=0;i<n;i++){ cout<<ans[i]<<' '; } cout<<'\n'; return 0; }

Compilation message (stderr)

birokracija.cpp: In function 'int dfs(int, int)':
birokracija.cpp:24:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   24 |     for(int i=0;i<adj[m].size();i++){
      |                 ~^~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...