結果
| 問題 |
No.1221 木 *= 3
|
| コンテスト | |
| ユーザー |
IKyopro
|
| 提出日時 | 2020-09-04 21:58:39 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 176 ms / 2,000 ms |
| コード長 | 1,123 bytes |
| コンパイル時間 | 3,082 ms |
| コンパイル使用メモリ | 204,484 KB |
| 最終ジャッジ日時 | 2025-01-14 05:40:37 |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 18 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;
template<class T> bool chmin(T& a,T b){if(a>b) {a = b; return true;} return false;}
template<class T> bool chmax(T& a,T b){if(a<b) {a = b; return true;} return false;}
#define debug(x) cerr << #x << " = " << (x) << endl;
int main(){
cin.tie(0);
ios::sync_with_stdio(false);
int N;
cin >> N;
vec<ll> A(N),B(N);
for(auto& x:A) cin >> x;
for(auto& x:B) cin >> x;
vvec<int> g(N);
for(int i=0;i<N-1;i++){
int a,b;
cin >> a >> b;
a--; b--;
g[a].push_back(b);
g[b].push_back(a);
}
ll inf = 1e18;
vvec<ll> dp(N,vec<ll>(2,0));
auto dfs = [&](auto&& self,int cur,int par)->void{
for(auto& to:g[cur]) if(to!=par){
self(self,to,cur);
dp[cur][0] += max(dp[to][0],dp[to][1]);
dp[cur][1] += max(dp[to][0],dp[to][1]+B[to]+B[cur]);
}
dp[cur][0] += A[cur];
};
dfs(dfs,0,-1);
cout << max(dp[0][0],dp[0][1]) << "\n";
}
IKyopro