From 97f863619f00779c323b8adc77bd9053ed7ca31e Mon Sep 17 00:00:00 2001 From: songyc macbook Date: Thu, 20 Nov 2025 20:45:19 +0900 Subject: [PATCH] 20251120 baekjoon --- code_study/Baekjoon/python/1005.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 code_study/Baekjoon/python/1005.py diff --git a/code_study/Baekjoon/python/1005.py b/code_study/Baekjoon/python/1005.py new file mode 100644 index 0000000..188666c --- /dev/null +++ b/code_study/Baekjoon/python/1005.py @@ -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)) \ No newline at end of file