Submission #541247

#TimeUsernameProblemLanguageResultExecution timeMemory
541247Ahmad_HasanBirokracija (COCI18_birokracija)C++17
60 / 100
1099 ms13412 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() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); 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...