File tree Expand file tree Collapse file tree 1 file changed +29
-0
lines changed Expand file tree Collapse file tree 1 file changed +29
-0
lines changed Original file line number Diff line number Diff line change
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 )
You can’t perform that action at this time.
0 commit comments