-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsubordinates.cpp
More file actions
48 lines (46 loc) · 972 Bytes
/
Copy pathsubordinates.cpp
File metadata and controls
48 lines (46 loc) · 972 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/******************************************
* AUTHOR : Prabhat Ravi *
* NICK : prabhatravi/binaryfetch/binaryfetch_9 *
******************************************/
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
using namespace std;
#define LL long long
const int N = 2e5 + 5;
#define MOD 1000000007
#define dd double
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep1(i,b) for(int i=1;i<=b;i++)
#define pb push_back
#define mp make_pair
#define clr(x) x.clear()
#define sz(x) ((int)(x).size())
#define F first
#define S second
vector<int>g[N];
int c[N];
void dfs(int s) {
c[s] = 1;
for (auto e : g[s]) {
dfs(e);
c[s] += c[e];
}
}
int main() {
int n;
cin >> n;
for (int i = 1; i < n; ++i)
{
int x;
cin >> x;
x--;
g[x].pb(i);
}
dfs(0);
for (int i = 0; i < n; i++) {
cout << (c[i] - 1) << " ";
}
return 0;
}