-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathA_Party.cpp
More file actions
53 lines (43 loc) · 1.03 KB
/
Copy pathA_Party.cpp
File metadata and controls
53 lines (43 loc) · 1.03 KB
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
49
50
51
52
53
#include <bits/stdc++.h>
using namespace std;
#define yes {cout<<"YES"<<endl;}
#define no {cout<<"NO"<<endl;}
#define rep(i,a,b) for(int i = a; i < b; i++)
#define dep(x,a,b) for(int x = a; x >= b; --x)
#define vb v.begin()
#define ve v.end()
#define int long long
#define endl '\n';
const int MOD = 1e9 + 7;
int lcm(int a,int b) { return a/__gcd(a,b)*b; }
vector<vector<int>> adj;
vector<int> depth;
void dfs(int root, int d = 0){
depth[root] = d;
rep(i,0,adj[root].size()){
dfs(adj[root][i],d+1);
}
}
void solve(){
int n; cin>>n;
vector<int> roots;
rep(i,0,n){
int v; cin>>v;
if(v!=-1){
adj[v-1].push_back(i);
}
else{
roots.push_back(i);
}
}
rep(i,0,roots.size()){
dfs(roots[i]);
}
int maxi = *max_element(depth.begin(),depth.end());
cout<<maxi+1<<endl;
}
signed main(){
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
solve();
}