結果
問題 | No.1221 木 *= 3 |
ユーザー |
![]() |
提出日時 | 2020-09-05 00:42:52 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 67 ms / 2,000 ms |
コード長 | 1,146 bytes |
コンパイル時間 | 2,357 ms |
コンパイル使用メモリ | 187,176 KB |
実行使用メモリ | 16,256 KB |
最終ジャッジ日時 | 2024-11-26 21:16:42 |
合計ジャッジ時間 | 4,384 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 18 |
ソースコード
#pragma GCC optimize ("O2")#pragma GCC target ("avx2")#include<bits/stdc++.h>using namespace std;typedef long long ll;#define rep(i, n) for(int i = 0; i < (n); i++)#define rep1(i, n) for(int i = 1; i <= (n); i++)#define co(x) cout << (x) << "\n"#define cosp(x) cout << (x) << " "#define ce(x) cerr << (x) << "\n"#define cesp(x) cerr << (x) << " "#define pb push_back#define mp make_pair#define chmin(x, y) x = min(x, y)#define chmax(x, y) x = max(x, y)#define Would#define you#define pleaseint N;int A[100001], B[100001];vector<int> E[100001];pair<ll, ll> dfs(int u, int mae) {ll kari1 = 0;ll kari2 = A[u];for (auto to : E[u]) {if (mae != to) {auto tmp = dfs(to, u);ll tmp1 = tmp.first;ll tmp2 = tmp.second;kari1 += max(B[u] + B[to] + tmp1, tmp2);kari2 += max(tmp1, tmp2);}}return mp(kari1, kari2);}int main() {cin.tie(0);ios::sync_with_stdio(false);cin >> N;rep1(i, N) cin >> A[i];rep1(i, N) cin >> B[i];rep(i, N - 1) {int u, v;cin >> u >> v;E[u].pb(v);E[v].pb(u);}auto tmp = dfs(1, -1);co(max(tmp.first, tmp.second));Would you please return 0;}