結果
問題 |
No.417 チューリップバブル
|
ユーザー |
|
提出日時 | 2017-05-30 23:10:31 |
言語 | D (dmd 2.109.1) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,498 bytes |
コンパイル時間 | 900 ms |
コンパイル使用メモリ | 123,504 KB |
実行使用メモリ | 13,752 KB |
最終ジャッジ日時 | 2024-06-12 19:36:03 |
合計ジャッジ時間 | 29,287 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 34 TLE * 2 -- * 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; if (ii > M) break; 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]); } } tmp[cur] = tmp[tar].dup; cur ^= 1; tar ^= 1; } //if (n == 0) tmp[cur].writeln; foreach (i; 0..M+1) dp[n][i] = tmp[cur][i] + U[n]; } dfs(0, -1); dp[0].reduce!max.writeln; }