-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy path트리_전성만.cpp
68 lines (60 loc) · 1.04 KB
/
트리_전성만.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
// https://www.acmicpc.net/problem/1068
#include <iostream>
using namespace std;
int v[50][50];
int cnt = 0, n, del;
void fnd(int m) {
int chk = 0;
for(int i = 0; i < n; i++) {
if (v[m][i] == del)
{
v[m][i] = -1;
}
if (v[m][i] != -1)
{
fnd(v[m][i]);
}
if (v[m][i] == -1)
{
chk++;
}
}
if(chk == n)
{
cnt++;
return;
}
}
int main() {
fill (&v[0][0], &v[50-1][2], -1);
cin >> n;
int t;
int root;
for (int i = 0; i < n; i++)
{
cin >> t;
if(~t)
{
for (int j = 0; j < n; j++)
{
if (v[t][j] == -1)
{
v[t][j] = i;
break;
}
}
}
else
{
root = i;
}
}
cin >> del;
if (del == root) {
cout << 0 << endl;
return 0;
}
fnd(root);
cout << cnt << endl;
return 0;
}