1
import queue
2

3

4
class Solution:
5
def numOfMinutes(
6
self, n: int, headID: int, manager: List[int], time: List[int]
7
) -> int:
8
nodes = []
9
for i in range(n):
10
nodes.append([])
11
for i in range(n):
12
if i != headID:
13
nodes[manager[i]].append(i)
14

15
q = queue.LifoQueue()
16
q.put([headID, 0])
17
ans = 0
18
while not q.empty():
19
cur = q.get()
20
for nxt in nodes[cur[0]]:
21
q.put([nxt, cur[1] + time[cur[0]]])
22
ans = max(ans, cur[1] + time[cur[0]])
23
return ans

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0