結果

問題 No.1221 木 *= 3
ユーザー 双六双六
提出日時 2020-09-07 02:42:33
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 971 bytes
コンパイル時間 274 ms
コンパイル使用メモリ 82,432 KB
実行使用メモリ 219,520 KB
最終ジャッジ日時 2024-05-06 21:45:09
合計ジャッジ時間 6,439 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
53,632 KB
testcase_01 AC 42 ms
53,632 KB
testcase_02 AC 41 ms
54,400 KB
testcase_03 AC 39 ms
54,132 KB
testcase_04 AC 41 ms
53,504 KB
testcase_05 AC 40 ms
54,144 KB
testcase_06 AC 38 ms
54,144 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 168 ms
104,064 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 172 ms
102,912 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys; input = sys.stdin.buffer.readline
sys.setrecursionlimit(10**7)
from collections import defaultdict
con = 10 ** 9 + 7; INF = float("inf")

def getlist():
	return list(map(int, input().split()))

class Graph(object):
	def __init__(self):
		self.graph = defaultdict(list)

	def __len__(self):
		return len(self.graph)

	def add_edge(self, a, b):
		self.graph[a].append(b)

def DFS(G, DPA, DPB, B, visit, node):
	for i in G.graph[node]:
		if visit[i] != 1:
			visit[i] = 1
			DFS(G, DPA, DPB, B, visit, i)
			DPA[node] += max(DPA[i], DPB[i])
			DPB[node] += max(DPA[i], B[node] + B[i])

#処理内容
def main():
	N = int(input())
	A = getlist()
	B = getlist()
	G = Graph()
	for i in range(N - 1):
		u, v = getlist()
		u -= 1; v -= 1
		G.add_edge(u, v)
		G.add_edge(v, u)

	#DFS
	DPA = [A[i] for i in range(N)]
	DPB = [0] * N
	visit = [0] * N
	visit[0] = 1
	DFS(G, DPA, DPB, B, visit, 0)
	ans = max(DPA[0], DPB[0])
	print(ans)


if __name__ == '__main__':
	main()
0