結果
問題 | No.1221 木 *= 3 |
ユーザー |
![]() |
提出日時 | 2020-09-06 00:16:02 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 167 ms / 2,000 ms |
コード長 | 1,211 bytes |
コンパイル時間 | 1,860 ms |
コンパイル使用メモリ | 182,648 KB |
実行使用メモリ | 18,304 KB |
最終ジャッジ日時 | 2024-11-29 06:22:46 |
合計ジャッジ時間 | 5,432 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 18 |
ソースコード
#pragma GCC optimize("O3")#include <bits/stdc++.h>#define ll long long#define rep(i,n) for(ll i=0;i<(n);i++)#define pll pair<ll,ll>#define pii pair<int,int>#define pq priority_queue#define pb push_back#define eb emplace_back#define fi first#define se second#define endl '\n'#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))using namespace std;const ll mod=1e9+7;ll n;vector<vector<int>> to;vector<ll> a,b,dp0,dp1;void dfs(int v,int p=-1){dp0[v]=a[v];for(auto x:to[v]){if(x==p) continue;dfs(x,v);dp0[v]+=max(dp0[x],dp1[x]);dp1[v]+=max(dp0[x],dp1[x]+b[x]+b[v]);}return ;}int main(){cin >> n;to=vector<vector<int>>(n);a=vector<ll>(n);b=vector<ll>(n);rep(i,n){cin >> a[i];}rep(i,n){cin >> b[i];}rep(i,n-1){ll u,v;cin >> u >> v;u--; v--;to[u].push_back(v);to[v].push_back(u);}dp0=vector<ll>(n);dp1=vector<ll>(n);dfs(0);cout << max(dp0[0],dp1[0]) << endl;return 0;}