結果

問題 No.417 チューリップバブル
ユーザー nebukuro09nebukuro09
提出日時 2017-05-30 23:10:31
言語 D
(dmd 2.106.1)
結果
TLE  
実行時間 -
コード長 1,498 bytes
コンパイル時間 1,621 ms
コンパイル使用メモリ 109,032 KB
実行使用メモリ 8,756 KB
最終ジャッジ日時 2023-09-03 13:47:34
合計ジャッジ時間 29,967 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
8,756 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 38 ms
4,376 KB
testcase_09 AC 93 ms
4,376 KB
testcase_10 AC 124 ms
4,380 KB
testcase_11 AC 587 ms
5,148 KB
testcase_12 AC 583 ms
4,380 KB
testcase_13 AC 206 ms
4,376 KB
testcase_14 AC 956 ms
5,688 KB
testcase_15 AC 55 ms
4,376 KB
testcase_16 AC 55 ms
4,380 KB
testcase_17 AC 484 ms
5,408 KB
testcase_18 AC 487 ms
5,168 KB
testcase_19 AC 485 ms
4,376 KB
testcase_20 TLE -
testcase_21 AC 1,972 ms
5,888 KB
testcase_22 AC 1,975 ms
5,932 KB
testcase_23 AC 1,970 ms
5,888 KB
testcase_24 AC 2 ms
4,380 KB
testcase_25 AC 1,986 ms
5,892 KB
testcase_26 AC 161 ms
4,852 KB
testcase_27 AC 1,370 ms
4,952 KB
testcase_28 AC 1,985 ms
5,948 KB
testcase_29 AC 1,961 ms
5,940 KB
testcase_30 AC 1,968 ms
5,944 KB
testcase_31 AC 1,967 ms
5,880 KB
testcase_32 AC 2 ms
4,376 KB
testcase_33 AC 48 ms
4,376 KB
testcase_34 AC 386 ms
4,376 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;
                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;
}
0