https://www.acmicpc.net/problem/1005
import sys
from collections import deque
si = sys.stdin.readline
def topology_sort() :
q = deque([])
for i in range(1,n+1) :
if indegrees[i] == 0 :
q.append(i)
dp[i] = times[i]
while q :
cur = q.popleft()
for x in graph[cur] :
indegrees[x] -= 1
dp[x] = max(dp[x], dp[cur] + times[x])
if indegrees[x] == 0 :
q.append(x)
T = int(si())
for _ in range(T) :
n,k = map(int,si().split())
times = [0] + list(map(int, si().split()))
dp = [0] * (n+1)
indegrees = [0] * (n+1)
graph = [[] for _ in range(n+1)]
for _ in range(k) :
u,v = map(int,si().split())
graph[u].append(v)
indegrees[v] += 1
w = int(si())
topology_sort()
print(dp[w])