-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbaekjoon_1068.cpp
54 lines (43 loc) · 914 Bytes
/
baekjoon_1068.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include <bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
using namespace std;
int arr[51][51];
int N;
int dfs(int start){
bool check = true;
int count = 0;
for(int i = 0; i < N; i ++){
if(arr[start][i] == 1){
check = false;
count += dfs(i);
}
}
if(check == true) return 1;
return count;
}
int main(void){
fastio;
memset(arr, 0, sizeof(arr));
cin >> N;
int start_node;
for(int i = 0; i < N; i++){
int temp;
cin >> temp;
if(temp == -1){
start_node = i;
continue;
}
arr[temp][i] = 1;
}
int erase;
cin >> erase;
if(erase == start_node){
cout << 0 << "\n";
return 0;
}
for(int i = 0; i < N; i++){
arr[i][erase] = 0;
}
cout << dfs(start_node) << "\n";
return 0;
}