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;
typedef long long ll;
const int N = 2e5+5;
ll ans[N], sz[N];
vector<int> child[N];
void dfs(int v)
{
sz[v] = 1;
for(int u : child[v])
{
dfs(u);
ans[v] += ans[u];
sz[v] += sz[u];
}
ans[v] += sz[v];
}
int main()
{
int n;
cin >> n;
for(int i = 2; i <= n; i ++)
{
int x;
cin >> x;
child[x].push_back(i);
}
dfs(1);
for(int i = 1; i <= n; i++)
cout << ans[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... |