結果
問題 | No.1221 木 *= 3 |
ユーザー |
|
提出日時 | 2020-10-09 05:03:34 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 207 ms / 2,000 ms |
コード長 | 550 bytes |
コンパイル時間 | 708 ms |
コンパイル使用メモリ | 72,448 KB |
実行使用メモリ | 19,328 KB |
最終ジャッジ日時 | 2024-07-20 06:38:04 |
合計ジャッジ時間 | 5,724 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 18 |
コンパイルメッセージ
main.cpp:19:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type] 19 | main() | ^~~~
ソースコード
#include<iostream>#include<vector>#include<algorithm>using namespace std;int N;vector<int>G[1<<17];long A[1<<17],B[1<<17];long dp[1<<17][2];void dfs(int u,int p){dp[u][0]=A[u];for(int v:G[u])if(v!=p){dfs(v,u);dp[u][0]+=max(dp[v][0],dp[v][1]);dp[u][1]+=max(dp[v][0],dp[v][1]+B[u]+B[v]);}}main(){cin>>N;for(int i=0;i<N;i++)cin>>A[i];for(int i=0;i<N;i++)cin>>B[i];for(int i=1;i<N;i++){int u,v;cin>>u>>v;u--,v--;G[u].push_back(v);G[v].push_back(u);}dfs(0,-1);cout<<max(dp[0][0],dp[0][1])<<endl;}