結果
問題 | No.417 チューリップバブル |
ユーザー |
|
提出日時 | 2020-07-12 02:37:22 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 567 ms / 2,000 ms |
コード長 | 994 bytes |
コンパイル時間 | 3,909 ms |
コンパイル使用メモリ | 201,612 KB |
最終ジャッジ日時 | 2025-01-11 19:52:30 |
ジャッジサーバーID (参考情報) |
judge3 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 40 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:40:21: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 40 | int n; scanf("%d%d",&n,&m); | ~~~~~^~~~~~~~~~~~~~ main.cpp:41:23: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 41 | rep(u,n) scanf("%d",&val[u]); | ~~~~~^~~~~~~~~~~~~~ main.cpp:44:33: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 44 | int u,v,c; scanf("%d%d%d",&u,&v,&c); | ~~~~~^~~~~~~~~~~~~~~~~~~
ソースコード
#include <bits/stdc++.h> #define rep(i,n) for(int i=0;i<(n);i++) using namespace std; template<class T> struct edge{ int to; T wt; edge(int to,const T& wt):to(to),wt(wt){} }; template<class T> using weighted_graph=vector<vector<edge<T>>>; template<class T> void add_undirected_edge(weighted_graph<T>& G,int u,int v,const T& wt){ G[u].emplace_back(v,wt); G[v].emplace_back(u,wt); } int m,val[200]; weighted_graph<int> T; vector<int> dfs(int u,int p){ vector<int> res(m+1); res[0]=val[u]; for(auto e:T[u]) if(e.to!=p) { int v=e.to; auto tmp=dfs(v,u),next=res; rep(w1,m+1) rep(w2,m+1) { if(w1+2*e.wt+w2>m) break; next[w1+2*e.wt+w2]=max(next[w1+2*e.wt+w2],res[w1]+tmp[w2]); } res=next; } return res; } int main(){ int n; scanf("%d%d",&n,&m); rep(u,n) scanf("%d",&val[u]); T.resize(n); rep(i,n-1){ int u,v,c; scanf("%d%d%d",&u,&v,&c); add_undirected_edge(T,u,v,c); } auto ans=dfs(0,-1); printf("%d\n",*max_element(ans.begin(),ans.end())); return 0; }