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 int long long
const int M = 2e5 + 1;
int subt[M],ans[M];
vector<int> nei[M];
void dfs(int u)
{
subt[u]=1;
for (int i:nei[u])
{
dfs(i);
ans[u]+=ans[i];
subt[u]+=subt[i];
}
ans[u]+=subt[u];
}
signed main()
{
int n;
cin>>n;
for (int i=2;i<=n;i++)
{
int u;
cin>>u;
nei[u].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... |