結果

問題 No.417 チューリップバブル
ユーザー nebukuro09nebukuro09
提出日時 2017-05-30 23:09:35
言語 D
(dmd 2.106.1)
結果
TLE  
実行時間 -
コード長 1,443 bytes
コンパイル時間 710 ms
コンパイル使用メモリ 108,936 KB
実行使用メモリ 6,236 KB
最終ジャッジ日時 2023-09-03 13:46:36
合計ジャッジ時間 9,231 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,384 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 40 ms
4,376 KB
testcase_09 AC 96 ms
4,388 KB
testcase_10 AC 130 ms
4,380 KB
testcase_11 AC 602 ms
4,380 KB
testcase_12 AC 599 ms
4,376 KB
testcase_13 AC 218 ms
4,384 KB
testcase_14 AC 969 ms
4,380 KB
testcase_15 AC 62 ms
4,380 KB
testcase_16 AC 62 ms
4,380 KB
testcase_17 AC 504 ms
4,380 KB
testcase_18 AC 511 ms
4,376 KB
testcase_19 AC 509 ms
5,416 KB
testcase_20 TLE -
testcase_21 TLE -
testcase_22 TLE -
testcase_23 TLE -
testcase_24 AC 2 ms
4,380 KB
testcase_25 TLE -
testcase_26 AC 173 ms
5,676 KB
testcase_27 AC 1,408 ms
6,236 KB
testcase_28 TLE -
testcase_29 TLE -
testcase_30 TLE -
testcase_31 TLE -
testcase_32 AC 2 ms
4,380 KB
testcase_33 AC 49 ms
4,376 KB
testcase_34 AC 620 ms
5,368 KB
testcase_35 TLE -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

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]);
                }
            }

            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;
}
0