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;
#define lalala ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
//#define endl '\n'
#define int long long int
//#define ll long long
#define pb push_back
#define p push
#define f first
#define s second
#define N 200200
vector<int> adj[N];
int sz[N],deg[N];
int dfs(int x){
sz[x]=0;
for(auto u:adj[x])sz[x]+=dfs(u);
for(auto u:adj[x]){
deg[x]+=deg[u]+sz[u];
}
sz[x]++;
deg[x]++;
return sz[x];
}
signed main(){
lalala;
int n;cin>>n;
for(int i=2;i<=n;i++){
int a;cin>>a;
adj[a].pb(i);
}
dfs(1);
for(int i=1;i<=n;i++)cout<<deg[i]<<" ";
cout<<endl;
}
# | 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... |