結果
問題 |
No.1221 木 *= 3
|
ユーザー |
![]() |
提出日時 | 2020-09-04 22:25:52 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 224 ms / 2,000 ms |
コード長 | 961 bytes |
コンパイル時間 | 5,222 ms |
コンパイル使用メモリ | 209,092 KB |
最終ジャッジ日時 | 2025-01-14 05:57:48 |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 18 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:34:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 34 | rep(i,N)scanf("%lld",&a[i]); | ~~~~~^~~~~~~~~~~~~~ main.cpp:35:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 35 | rep(i,N)scanf("%lld",&b[i]); | ~~~~~^~~~~~~~~~~~~~ main.cpp:38:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 38 | scanf("%d %d",&x,&y); | ~~~~~^~~~~~~~~~~~~~~
ソースコード
#include <bits/stdc++.h> using namespace std; #define rep(i,n) for (int i = 0; i < (n); ++i) #define modulo 1000000007 #define mod(mod_x) ((((long long)mod_x+modulo))%modulo) #define Inf 1000000000000000000 int N; vector<vector<int>> E; vector<long long> a,b; vector<vector<long long>> dp; void dfs(int now,int p){ dp[now][0] = a[now]; dp[now][1] = 0LL; for(int i=0;i<E[now].size();i++){ int to = E[now][i]; if(to==p)continue; dfs(to,now); dp[now][0] += max(dp[to][0],dp[to][1]); dp[now][1] += max(dp[to][0],dp[to][1] + b[to] + b[now]); } } int main(){ cin>>N; E.resize(N,vector<int>()); a.resize(N); b.resize(N); rep(i,N)scanf("%lld",&a[i]); rep(i,N)scanf("%lld",&b[i]); rep(i,N-1){ int x,y; scanf("%d %d",&x,&y); x--;y--; E[x].push_back(y); E[y].push_back(x); } dp.resize(N,vector<long long>(2,0LL)); dfs(0,-1); //rep(i,N)cout<<dp[i][0]<<','<<dp[i][1]<<endl; cout<<max(dp[0][0],dp[0][1])<<endl; return 0; }