結果
問題 | No.1221 木 *= 3 |
ユーザー |
![]() |
提出日時 | 2020-09-04 22:59:07 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
AC
|
実行時間 | 659 ms / 2,000 ms |
コード長 | 607 bytes |
コンパイル時間 | 99 ms |
コンパイル使用メモリ | 12,800 KB |
実行使用メモリ | 63,576 KB |
最終ジャッジ日時 | 2024-11-26 20:54:35 |
合計ジャッジ時間 | 10,472 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 18 |
ソースコード
import sysdef input(): return sys.stdin.readline().rstrip()sys.setrecursionlimit(1000000)n=int(input())a=list(map(int,input().split()))b=list(map(int,input().split()))edge=[[]for _ in range(n)]for _ in range(n-1):aa,bb=map(int,input().split())aa-=1bb-=1edge[aa].append(bb)edge[bb].append(aa)dp=[[a[i],0]for i in range(n)]def dfs(r,node):if len(edge[node])==1 and r!=-1:return dp[node]x=a[node]y=0for mode in edge[node]:if mode==r:continuexx,yy=dfs(node,mode)x+=max(xx,yy)y+=max(xx,b[node]+b[mode]+yy)return [x,y]x,y=dfs(-1,0)print(max(x,y))