#include <bits/stdc++.h>
using namespace std;
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];
}
int 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 |
1 |
Correct |
1 ms |
4956 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4956 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4956 KB |
Output is correct |
2 |
Correct |
1 ms |
4956 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4956 KB |
Output is correct |
2 |
Correct |
1 ms |
4956 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4956 KB |
Output is correct |
2 |
Correct |
2 ms |
4956 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
5468 KB |
Output is correct |
2 |
Correct |
7 ms |
5980 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
34 ms |
6744 KB |
Output is correct |
2 |
Correct |
20 ms |
7260 KB |
Output is correct |
3 |
Correct |
20 ms |
8540 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
59 ms |
10324 KB |
Output is correct |
2 |
Incorrect |
55 ms |
12884 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
57 ms |
10216 KB |
Output is correct |
2 |
Correct |
99 ms |
11860 KB |
Output is correct |
3 |
Incorrect |
55 ms |
14276 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
57 ms |
10068 KB |
Output is correct |
2 |
Correct |
63 ms |
12112 KB |
Output is correct |
3 |
Incorrect |
61 ms |
16660 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |