結果
問題 | No.1221 木 *= 3 |
ユーザー |
![]() |
提出日時 | 2020-09-05 03:09:59 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 162 ms / 2,000 ms |
コード長 | 911 bytes |
コンパイル時間 | 1,576 ms |
コンパイル使用メモリ | 174,736 KB |
実行使用メモリ | 16,896 KB |
最終ジャッジ日時 | 2024-11-27 03:59:31 |
合計ジャッジ時間 | 6,108 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 18 |
ソースコード
/*** @FileName a.cpp* @Author kanpurin* @Created 2020.09.05 03:09:52**/#include "bits/stdc++.h"using namespace std;typedef long long ll;int n;vector<vector<int>> g;vector<ll> a,b;pair<ll,ll> dfs(int v, int p = -1) {pair<ll,ll> ret = {a[v],0};for(int u : g[v]) {if (u == p) continue;auto t = dfs(u,v);ret.first += max(t.first,t.second);ret.second += max(b[u] + t.second + b[v], t.first);}return ret;}int main() {cin >> n;a.resize(n);b.resize(n);g.resize(n);for (int i = 0; i < n; i++) {cin >> a[i];}for (int i = 0; i < n; i++) {cin >> b[i];}for (int i = 0; i < n-1; i++) {int u,v;cin >> u >> v;u--;v--;g[u].push_back(v);g[v].push_back(u);}auto ans = dfs(0);cout << max(ans.first,ans.second) << endl;return 0;}