結果
| 問題 |
No.417 チューリップバブル
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2017-05-30 22:50:20 |
| 言語 | D (dmd 2.109.1) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,398 bytes |
| コンパイル時間 | 1,048 ms |
| コンパイル使用メモリ | 123,860 KB |
| 実行使用メモリ | 13,756 KB |
| 最終ジャッジ日時 | 2024-06-12 19:33:25 |
| 合計ジャッジ時間 | 29,490 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 8 WA * 25 TLE * 3 -- * 4 |
ソースコード
import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop;
alias Tuple!(int, "to", int, "cost") Edge;
void main() {
auto s = readln.split.map!(to!int);
auto N = s[0];
auto M = s[1];
auto U = N.iota.map!(_ => readln.chomp.to!int).array;
auto edges = new Edge[][](N);
foreach (i; 0..N-1) {
s = readln.split.map!(to!int);
edges[s[0]] ~= Edge(s[1], s[2]);
edges[s[1]] ~= Edge(s[0], s[2]);
}
auto dp = new int[][](N, M + 1);
void dfs(int n, int prev) {
foreach (m; edges[n])
if (m.to != prev)
dfs(m.to, n);
auto tmp = new int[][](2, M + 1);
int cur = 0;
int tar = 1;
foreach (m; edges[n]) {
if (m.to == prev)
continue;
foreach (i; 0..M+1) {
int ii = i + m.cost * 2;
foreach (j; 0..M+1) {
if (ii + j > M)
break;
tmp[tar][ii+j] = max(tmp[tar][ii+j], dp[m.to][i] + tmp[cur][j]);
}
}
fill(tmp[cur], 0);
cur ^= 1;
tar ^= 1;
}
foreach (i; 0..M+1) dp[n][i] = tmp[cur][i] + U[n];
}
dfs(0, -1);
dp[0].reduce!max.writeln;
}