結果

問題 No.1221 木 *= 3
ユーザー uzzyuzzy
提出日時 2020-09-05 00:42:52
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 68 ms / 2,000 ms
コード長 1,146 bytes
コンパイル時間 2,596 ms
コンパイル使用メモリ 187,052 KB
実行使用メモリ 16,256 KB
最終ジャッジ日時 2024-05-05 03:52:37
合計ジャッジ時間 4,299 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
5,888 KB
testcase_01 AC 4 ms
5,760 KB
testcase_02 AC 3 ms
5,888 KB
testcase_03 AC 3 ms
5,760 KB
testcase_04 AC 3 ms
5,760 KB
testcase_05 AC 3 ms
5,888 KB
testcase_06 AC 3 ms
5,888 KB
testcase_07 AC 63 ms
16,256 KB
testcase_08 AC 64 ms
16,000 KB
testcase_09 AC 66 ms
16,128 KB
testcase_10 AC 65 ms
16,000 KB
testcase_11 AC 68 ms
16,000 KB
testcase_12 AC 60 ms
10,008 KB
testcase_13 AC 58 ms
9,884 KB
testcase_14 AC 58 ms
9,880 KB
testcase_15 AC 56 ms
9,880 KB
testcase_16 AC 58 ms
9,760 KB
testcase_17 AC 63 ms
9,728 KB
testcase_18 AC 62 ms
9,856 KB
testcase_19 AC 64 ms
9,856 KB
testcase_20 AC 65 ms
9,728 KB
testcase_21 AC 65 ms
9,728 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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 please

int 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;
}
0