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 MAXN 200100
vector<int> grafo[MAXN];
int resp[MAXN], pai[MAXN], mark[MAXN];
void dfs (int u, int num, int sum){
mark[u]=1;
resp[u]+=sum;
if(pai[u]==0)return;
if(mark[pai[u]]==0){
num++;
}
dfs(pai[u], num, (sum+num));
}
int main(){
int n;
cin >> n;
for(int i=2; i<=n; i++){
int p;
cin >> p;
grafo[p].push_back(i);
pai[i]=p;
}
pai[1]=0;
for(int i=2; i<=n; i++){
if(grafo[i].size() == 0){
dfs(i, 1, 1);
}
}
for(int i=1; i<=n; i++){
cout << resp[i] << " ";
}
cout << endl;
return 0;
}
# | 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... |