-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1135.cpp
More file actions
33 lines (33 loc) · 695 Bytes
/
1135.cpp
File metadata and controls
33 lines (33 loc) · 695 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
#include <bits/stdc++.h>
#define ll long long
#define X first
#define Y second
#define pii pair<int,int>
using namespace std;
int n;
vector<int> child[50];
int dfs(int cur) {
if(child[cur].size() == 0) return 0;
vector<int> v;
for(int nxt : child[cur]) {
v.push_back(dfs(nxt));
}
int ret = 0;
int len = child[cur].size();
sort(v.begin(), v.end());
for(int i : v) {
ret = max(ret, i + len--);
}
return ret;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cin >> n;
for(int i = 0; i < n; i++) {
int pe; cin >> pe;
if(pe == -1) continue;
child[pe].push_back(i);
}
cout << dfs(0);
}