29 lines
725 B
Python
29 lines
725 B
Python
import sys
|
|
sys.setrecursionlimit(10**6)
|
|
input = sys.stdin.readline
|
|
|
|
for _ in range(int(input())) :
|
|
N, K = map(int, input().split())
|
|
|
|
build_time = [0] + list(map(int, input().split()))
|
|
|
|
build_info = [[] for _ in range(N+1)]
|
|
for _ in range(K) :
|
|
x, y = map(int, input().split())
|
|
build_info[y].append(x)
|
|
|
|
W = int(input())
|
|
|
|
dp = [-1]*(N+1)
|
|
|
|
def solve(target) :
|
|
if dp[target] == -1 :
|
|
max_build_time = 0
|
|
for prev in build_info[target] :
|
|
max_build_time = max(max_build_time, solve(prev))
|
|
|
|
dp[target] = max_build_time + build_time[target]
|
|
|
|
return dp[target]
|
|
|
|
print(solve(W)) |