# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
541246 | Ahmad_Hasan | Birokracija (COCI18_birokracija) | C++17 | 1089 ms | 14536 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |