結果
問題 | No.1221 木 *= 3 |
ユーザー | kappybar |
提出日時 | 2020-09-04 22:16:35 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 161 ms / 2,000 ms |
コード長 | 1,000 bytes |
コンパイル時間 | 1,466 ms |
コンパイル使用メモリ | 169,560 KB |
実行使用メモリ | 18,560 KB |
最終ジャッジ日時 | 2024-05-04 22:48:46 |
合計ジャッジ時間 | 5,051 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 3 ms
5,888 KB |
testcase_01 | AC | 2 ms
6,016 KB |
testcase_02 | AC | 3 ms
5,888 KB |
testcase_03 | AC | 3 ms
5,888 KB |
testcase_04 | AC | 3 ms
6,016 KB |
testcase_05 | AC | 3 ms
6,016 KB |
testcase_06 | AC | 2 ms
5,888 KB |
testcase_07 | AC | 153 ms
18,560 KB |
testcase_08 | AC | 152 ms
18,304 KB |
testcase_09 | AC | 149 ms
18,504 KB |
testcase_10 | AC | 151 ms
18,432 KB |
testcase_11 | AC | 154 ms
18,432 KB |
testcase_12 | AC | 150 ms
12,312 KB |
testcase_13 | AC | 135 ms
12,256 KB |
testcase_14 | AC | 144 ms
12,188 KB |
testcase_15 | AC | 151 ms
12,188 KB |
testcase_16 | AC | 150 ms
12,168 KB |
testcase_17 | AC | 161 ms
12,160 KB |
testcase_18 | AC | 145 ms
12,288 KB |
testcase_19 | AC | 145 ms
12,160 KB |
testcase_20 | AC | 146 ms
12,160 KB |
testcase_21 | AC | 147 ms
12,160 KB |
ソースコード
#include <bits/stdc++.h> #define rep(i,n) for(int i=0;i<(int)(n);i++) using namespace std; using ll = long long ; using P = pair<int,int> ; using pll = pair<long long,long long>; constexpr int INF = 1e9; constexpr long long LINF = 1e17; constexpr int MOD = 1000000007; constexpr double PI = 3.14159265358979323846; int n; vector<int> tree[100005]; ll a[100005]; ll b[100005]; ll dp[100005][2]; pll dfs(int i,int before){ ll one = a[i]; ll two = 0; for(int j:tree[i]){ if(j==before) continue; pll now = dfs(j,i); one += max(now.first,now.second); two += max(now.first,now.second+b[j]+b[i]); } dp[i][0] = one; dp[i][1] = two; return pll(one,two); } int main(){ cin >> n; rep(i,n) cin >> a[i]; rep(i,n) cin >> b[i]; rep(i,n-1){ int u,v; cin >> u >> v; --u;--v; tree[u].push_back(v); tree[v].push_back(u); } dfs(0,-1); cout << max(dp[0][0],dp[0][1]) << endl; return 0; }