20251120 baekjoon
This commit is contained in:
parent
3cb8f2e915
commit
97f863619f
29
code_study/Baekjoon/python/1005.py
Normal file
29
code_study/Baekjoon/python/1005.py
Normal file
@ -0,0 +1,29 @@
|
||||
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))
|
||||
Loading…
x
Reference in New Issue
Block a user