結果
問題 | No.1221 木 *= 3 |
ユーザー | kappybar |
提出日時 | 2020-09-04 22:16:35 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 176 ms / 2,000 ms |
コード長 | 1,000 bytes |
コンパイル時間 | 2,235 ms |
コンパイル使用メモリ | 166,836 KB |
実行使用メモリ | 18,488 KB |
最終ジャッジ日時 | 2023-08-17 16:11:59 |
合計ジャッジ時間 | 5,633 ms |
ジャッジサーバーID (参考情報) |
judge15 / judge13 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 4 ms
6,868 KB |
testcase_01 | AC | 4 ms
6,880 KB |
testcase_02 | AC | 3 ms
6,792 KB |
testcase_03 | AC | 4 ms
6,812 KB |
testcase_04 | AC | 3 ms
6,876 KB |
testcase_05 | AC | 4 ms
6,764 KB |
testcase_06 | AC | 4 ms
6,812 KB |
testcase_07 | AC | 175 ms
18,488 KB |
testcase_08 | AC | 171 ms
18,252 KB |
testcase_09 | AC | 173 ms
18,424 KB |
testcase_10 | AC | 175 ms
18,272 KB |
testcase_11 | AC | 175 ms
18,364 KB |
testcase_12 | AC | 161 ms
12,008 KB |
testcase_13 | AC | 154 ms
12,240 KB |
testcase_14 | AC | 158 ms
12,112 KB |
testcase_15 | AC | 156 ms
11,944 KB |
testcase_16 | AC | 158 ms
11,956 KB |
testcase_17 | AC | 176 ms
12,076 KB |
testcase_18 | AC | 171 ms
12,140 KB |
testcase_19 | AC | 175 ms
12,128 KB |
testcase_20 | AC | 171 ms
12,072 KB |
testcase_21 | AC | 174 ms
12,044 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; }