結果

問題 No.1221 木 *= 3
ユーザー 钟梓皓钟梓皓
提出日時 2020-09-04 21:47:56
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 66 ms / 2,000 ms
コード長 796 bytes
コンパイル時間 1,675 ms
コンパイル使用メモリ 195,072 KB
最終ジャッジ日時 2025-01-14 05:29:44
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 18
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:24:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   24 |     scanf("%d", &n);
      |     ~~~~~^~~~~~~~~~
main.cpp:26:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   26 |         scanf("%d", &a[i]);
      |         ~~~~~^~~~~~~~~~~~~
main.cpp:29:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   29 |         scanf("%d", &b[i]);
      |         ~~~~~^~~~~~~~~~~~~
main.cpp:32:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   32 |         scanf("%d%d", &u, &v);
      |         ~~~~~^~~~~~~~~~~~~~~~

ソースコード

diff #
プレゼンテーションモードにする

#include <bits/stdc++.h>
const int N = 100010;
using ll = long long;
int a[N], b[N];
std::vector<int> e[N];
ll dp[N][2];
void dfs(int u, int fa){
dp[u][0] = a[u];
for (auto v : e[u]){
if (v == fa){
continue;
}
dfs(v, u);
dp[u][0] += std::max(dp[v][0], dp[v][1]);
dp[u][1] += std::max(dp[v][0], dp[v][1] + b[u] + b[v]);
}
}
int main(){
int n;
scanf("%d", &n);
for (int i = 1; i <= n; ++ i){
scanf("%d", &a[i]);
}
for (int i = 1; i <= n; ++ i){
scanf("%d", &b[i]);
}
for (int i = 0, u, v; i < n - 1; ++ i){
scanf("%d%d", &u, &v);
e[u].emplace_back(v);
e[v].emplace_back(u);
}
dfs(1, 0);
printf("%lld\n", std::max(dp[1][0], dp[1][1]));
return 0;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0