#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAXN=2e5+10;
int n, m;
int in[MAXN], qc[MAXN];
ll resposta[MAXN];
vector <int> graph[MAXN];
int dfs(int u, int f){
for(int v: graph[u]){
if(v!=f){
int qv=dfs(v, u);
qc[u]+=qv;
resposta[u]+=resposta[v]+qv;
}
}
resposta[u]++;
qc[u]++;
return qc[u];
}
int main(){
cin >> n;
for(int i=2;i<=n;++i){
cin >> in[i];
graph[i].push_back(in[i]);
graph[in[i]].push_back(i);
}
dfs(1, 1);
for(int i=1;i<=n;++i){
cout << resposta[i] << " \n"[i==n];
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
4984 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
5236 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
5236 KB |
Output is correct |
2 |
Correct |
6 ms |
5236 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
5236 KB |
Output is correct |
2 |
Correct |
6 ms |
5280 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
5280 KB |
Output is correct |
2 |
Correct |
6 ms |
5280 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
19 ms |
6176 KB |
Output is correct |
2 |
Correct |
26 ms |
6564 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
65 ms |
8764 KB |
Output is correct |
2 |
Correct |
53 ms |
8820 KB |
Output is correct |
3 |
Correct |
65 ms |
10064 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
196 ms |
15260 KB |
Output is correct |
2 |
Correct |
152 ms |
17052 KB |
Output is correct |
3 |
Correct |
149 ms |
29060 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
209 ms |
29060 KB |
Output is correct |
2 |
Correct |
152 ms |
29060 KB |
Output is correct |
3 |
Correct |
153 ms |
29060 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
185 ms |
29060 KB |
Output is correct |
2 |
Correct |
150 ms |
29060 KB |
Output is correct |
3 |
Correct |
161 ms |
29060 KB |
Output is correct |