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>
#define PB push_back
using namespace std;
typedef long long ll;
const int N = 200100;
vector<int> g[N];
int n, siz[N];
ll sum[N];
int main(){
ios_base::sync_with_stdio(0); cin.tie(0);
cin >> n;
for (int i = 1; i < n; i++){
int x; cin >> x; x--;
g[x].PB(i);
}
for (int v = n - 1; v >= 0; v--){
siz[v] = 1;
sum[v] = 0;
for (int u : g[v]){
siz[v] += siz[u];
sum[v] += sum[u];
}
sum[v] += siz[v];
}
for (int i = 0; i < n; i++)
cout << sum[i] << " ";
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... |