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;
long long f[200001];
int sz[200001];
vector<int> v[200001];
void dfs(int cur,int prev)
{
f[cur]=1;
sz[cur]=1;
for(auto node : v[cur])
{
if(node==prev)continue;
dfs(node,cur);
f[cur]+=f[node]+sz[node];
sz[cur]+=sz[node];
}
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n,x;
cin >> n;
for(int i=1;i<n;i++)
{
cin >> x;
x--;
v[i].push_back(x);
v[x].push_back(i);
}
dfs(0,-1);
for(int i=0;i<n;i++)
{
cout << f[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... |