Skip to content

Commit 4fb85c9

Browse files
committed
알고리즘
1 parent 2445179 commit 4fb85c9

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

Baekjoon_file/1135.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
n = int(input()) # 회사 직원수
2+
3+
tree = [[] for _ in range(n)] # tree
4+
input_list = list(map(int,input().split()))
5+
child_cnt = [0 for _ in range(n)]
6+
7+
def find_child(parent):
8+
global child_cnt
9+
print(child_cnt)
10+
child_node = [] # child 개수 담을 변수
11+
if tree[parent] == []: # 만약 자식 노드가 없다 -> 0 으로 초기화
12+
child_cnt[parent] = 0
13+
else:
14+
for child in tree[parent]: # 자식노드 탐색
15+
find_child(child)
16+
child_node.append(child_cnt[child])
17+
18+
child_node.sort(reverse=True)
19+
child_node = [child_node[i] + i + 1 for i in range(len(child_node))]
20+
child_cnt[parent] = max(child_node)
21+
22+
23+
for i in range(1,len(input_list)):
24+
tree[input_list[i]].append(i) # node 추가
25+
26+
27+
28+
find_child(0)
29+
print(child_cnt)

0 commit comments

Comments
 (0)