-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path3182.cpp
More file actions
52 lines (51 loc) · 1.24 KB
/
Copy path3182.cpp
File metadata and controls
52 lines (51 loc) · 1.24 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
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <queue>
using namespace std;
void dfs(int start, int* count, vector<int> graph[], bool check[]){
if(count != 0){
check[start] = true;
}
// cout <<"start: "<<start <<" check: " << check[start]<<endl;
*count = *count + 1;
int size = graph[start].size();
for(int i=0;i < size;i++){
int next = graph[start][i];
if(check[next]==false){
dfs(next, count, graph,check);
}
}
}
int main(){
int N,answer =1;
cin >> N;
vector<int> graph[N+1];
bool check[N+1];
int count[N+1];
fill(count, count+N+1,0);
fill(check, check+N+1,false);
int input;
for(int i = 1;i<N+1;i++){
cin >> input;
graph[i].push_back(input);
}
for(int i =1; i<=N;i++){
sort(graph[i].begin(),graph[i].end());
}
for(int start = 1; start<=N; start++){
dfs(start,&count[start], graph,check);
fill(check, check+N+1,false);
}
int max_count =0;
for(int i = 1; i<= N; i++){
// cout <<"count :" << count[i] <<endl;
if(count[i] > max_count){
max_count = count[i];
answer = i;
}
}
cout << answer;
return 0;
}