-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1005.py
40 lines (35 loc) · 1.1 KB
/
1005.py
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
# class Node:
# preNodeList = None
# constructTime = -1
# ownConstructTime = None
# def __init__(self, ownConstructTime):
# self.preNodeList = []
# self.ownConstructTime = ownConstructTime
preNode = [None]
constructTime = [None]
ownConstructTime = None
def caculateConstructTime(parent):
if constructTime[parent] == -1:
maxTime = 0
for child in preNode[parent]:
childTime = caculateConstructTime(child)
if childTime > maxTime:
maxTime = childTime
maxTime += ownConstructTime[parent]
constructTime[parent] = maxTime
return constructTime[parent]
T = int(input())
for t in range(T):
preNode = [None]
constructTime = [None]
ownConstructTime = None
N, K = map(int, input().split(' '))
ownConstructTime = [None]+list(map(int, input().split(' ')))
for n in range(N):
preNode.append([])
constructTime.append(-1)
for k in range(K):
x, y = map(int, input().split(' '))
preNode[y].append(x)
D = int(input())
print(caculateConstructTime(D))