-
Notifications
You must be signed in to change notification settings - Fork 35
/
Copy path115A - Party.cpp
36 lines (31 loc) · 898 Bytes
/
115A - Party.cpp
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
#include <bits/stdc++.h>
using namespace std;
std::vector<int>superviser;
int find_depth(int depth,int employe);
int main(){
int n;
scanf("%d",&n);
superviser.push_back(-1);
//inputing the superviser of each employe
for(int i=1; i<=n; i++) {
int temp;
cin>>temp;
superviser.push_back(temp);
}
//finding depth of the tree
int maxdepth=1;
for(int i=1; i<=n; i++) {
int depth=1;
int employe=i;
depth=find_depth(depth,employe);
if(depth>maxdepth)
maxdepth=depth;
}
cout<<maxdepth<<endl;
}
int find_depth(int depth,int employe){
if(superviser[employe]==-1)
return depth;
else
return find_depth(depth+1,superviser[employe]);
}