結果

問題 No.417 チューリップバブル
ユーザー Yukino DX.Yukino DX.
提出日時 2023-11-18 12:07:57
言語 Rust
(1.77.0)
結果
TLE  
実行時間 -
コード長 1,605 bytes
コンパイル時間 784 ms
コンパイル使用メモリ 183,776 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2023-11-18 12:08:30
合計ジャッジ時間 29,353 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,676 KB
testcase_01 AC 1 ms
6,676 KB
testcase_02 AC 1 ms
6,676 KB
testcase_03 AC 0 ms
6,676 KB
testcase_04 AC 1 ms
6,676 KB
testcase_05 AC 1 ms
6,676 KB
testcase_06 AC 1 ms
6,676 KB
testcase_07 AC 1 ms
6,676 KB
testcase_08 AC 22 ms
6,676 KB
testcase_09 AC 56 ms
6,676 KB
testcase_10 AC 75 ms
6,676 KB
testcase_11 AC 351 ms
6,676 KB
testcase_12 AC 362 ms
6,676 KB
testcase_13 AC 140 ms
6,676 KB
testcase_14 AC 586 ms
6,676 KB
testcase_15 AC 38 ms
6,676 KB
testcase_16 AC 38 ms
6,676 KB
testcase_17 AC 295 ms
6,676 KB
testcase_18 AC 326 ms
6,676 KB
testcase_19 AC 306 ms
6,676 KB
testcase_20 AC 1,208 ms
6,676 KB
testcase_21 AC 1,210 ms
6,676 KB
testcase_22 AC 1,226 ms
6,676 KB
testcase_23 AC 1,209 ms
6,676 KB
testcase_24 AC 1 ms
6,676 KB
testcase_25 AC 1,219 ms
6,676 KB
testcase_26 AC 105 ms
6,676 KB
testcase_27 AC 850 ms
6,676 KB
testcase_28 AC 1,218 ms
6,676 KB
testcase_29 AC 1,204 ms
6,676 KB
testcase_30 AC 1,217 ms
6,676 KB
testcase_31 AC 1,180 ms
6,676 KB
testcase_32 AC 1 ms
6,676 KB
testcase_33 AC 28 ms
6,676 KB
testcase_34 AC 242 ms
6,676 KB
testcase_35 TLE -
testcase_36 TLE -
testcase_37 TLE -
testcase_38 TLE -
testcase_39 TLE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#![allow(unused_imports)]
// use itertools::Itertools;
// use proconio::input;
// use proconio::marker::*;
use std::cmp::Reverse;
use std::collections::*;

fn main() {
    let nm = read_ints();
    let n = nm[0];
    let m = nm[1];
    let mut u = vec![0; n];
    for i in 0..n {
        let ui = read_int();
        u[i] = ui;
    }

    let mut g = vec![vec![]; n];
    for _ in 0..n - 1 {
        let abc = read_ints();
        g[abc[0]].push((abc[1], abc[2]));
        g[abc[1]].push((abc[0], abc[2]));
    }

    let mut dp = vec![vec![0; m + 1]; n];

    f(&g, &u, m, 0, n, &mut dp);
    let ans = dp[0][m];
    println!("{}", ans);
}

fn f(
    g: &Vec<Vec<(usize, usize)>>,
    u: &Vec<usize>,
    m: usize,
    crr: usize,
    prv: usize,
    dp: &mut Vec<Vec<usize>>,
) {
    for &(nxt, _) in g[crr].iter() {
        if prv == nxt {
            continue;
        }

        f(g, u, m, nxt, crr, dp);
    }

    for &(nxt, cost) in g[crr].iter() {
        for s in (0..=m).rev() {
            for t in (0..=m).take_while(|&t| s >= t + 2 * cost) {
                dp[crr][s] = dp[crr][s].max(dp[nxt][t] + dp[crr][s - (t + 2 * cost)])
            }
        }
    }

    for t in 0..=m {
        dp[crr][t] += u[crr];
    }
}

use std::io;
fn read_ints() -> Vec<usize> {
    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.trim()
        .split_whitespace()
        .map(|s| s.parse().unwrap())
        .collect()
}

fn read_int() -> usize {
    let mut buffer = String::new();
    io::stdin().read_line(&mut buffer).unwrap();
    buffer.trim().parse().unwrap()
}
0