結果
| 問題 |
No.417 チューリップバブル
|
| コンテスト | |
| ユーザー |
yixuan peng
|
| 提出日時 | 2025-04-19 13:00:37 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 436 ms / 2,000 ms |
| コード長 | 994 bytes |
| コンパイル時間 | 2,384 ms |
| コンパイル使用メモリ | 193,956 KB |
| 実行使用メモリ | 7,844 KB |
| 最終ジャッジ日時 | 2025-04-19 13:00:47 |
| 合計ジャッジ時間 | 8,283 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 40 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:39:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
39 | scanf("%d%d",&n,&m);
| ~~~~~^~~~~~~~~~~~~~
main.cpp:41:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
41 | scanf("%d",&a[i]);
| ~~~~~^~~~~~~~~~~~
main.cpp:43:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
43 | scanf("%d%d%d",&x,&y,&z);
| ~~~~~^~~~~~~~~~~~~~~~~~~
ソースコード
#include<bits/stdc++.h>
using namespace std;
const int N=200+5,M=2000+5;
int n,m,cnt,ans,a[N],f[N][M],head[N];
struct edge{
int to,w,nxt;
}e[N<<1];
void add(int u,int v,int w){
e[++cnt]=(edge){v,w,head[u]};
head[u]=cnt;
}
void dfs(int u,int fa){
// cout<<u<<' '<<fa<<endl;
for(int i=0;i<=m;i++)
f[u][i]=a[u];
for(int i=head[u];i;i=e[i].nxt){
int v=e[i].to;
if(v==fa) continue;
// cout<<v<<' ';
dfs(v,u);
for(int j=m;j>=2*e[i].w;j--)
for(int k=2*e[i].w;k<=j;k++)
f[u][j]=max(f[u][j],f[v][k-2*e[i].w]+f[u][j-k]);
}
// cout<<u<<endl;
// for(int i=0;i<=m;i++)
// if(f[u][i]) cout<<i<<' '<<f[u][i]<<endl;
// cout<<endl;
}
int main(){
// freopen("tulip.in","r",stdin);
// freopen("tulip.out","w",stdout);
scanf("%d%d",&n,&m);
for(int i=1;i<=n;i++)
scanf("%d",&a[i]);
for(int i=1,x,y,z;i<n;i++){
scanf("%d%d%d",&x,&y,&z);
x++,y++;
add(x,y,z),add(y,x,z);
}
dfs(1,0);
// cout<<0;
for(int i=0;i<=m;i++)
ans=max(ans,f[1][i]);
printf("%d",ans);
return 0;
}
yixuan peng