提出 #40923208


ソースコード 拡げる

use proconio::{input, marker::Usize1};

fn dfs(dp: &mut Vec<usize>, edges: &Vec<Vec<usize>>, u: usize) {
    let mut cs = vec![];
    for v in edges[u].iter().copied() {
        dfs(dp, edges, v);
        cs.push(dp[v]);
    }
    dp[u] = *cs.iter().max().unwrap_or(&0) + *cs.iter().min().unwrap_or(&0) + 1;
}

fn main() {
    input! {
        n: usize,
        b: [Usize1; n - 1]
    }

    let mut edges = vec![vec![]; n];
    for (i, b_i) in b.iter().copied().enumerate() {
        edges[b_i].push(i + 1);
    }

    let mut dp = vec![0_usize; n];
    dfs(&mut dp, &edges, 0);

    let ans = dp[0];
    println!("{}", ans);
}

提出情報

提出日時
問題 C - 高橋君の給料
ユーザ bouzuya
言語 Rust (1.42.0)
得点 100
コード長 629 Byte
結果 AC
実行時間 6 ms
メモリ 2124 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 100 / 100
結果
AC × 4
AC × 22
セット名 テストケース
Sample example_0.txt, example_1.txt, example_2.txt, example_3.txt
All example_0.txt, example_1.txt, example_2.txt, example_3.txt, maxrand_0.txt, maxrand_1.txt, maxrand_2.txt, random_0.txt, random_1.txt, random_2.txt, random_3.txt, random_4.txt, random_5.txt, random_6.txt, random_7.txt, random_8.txt, random_9.txt, special_0.txt, example_0.txt, example_1.txt, example_2.txt, example_3.txt
ケース名 結果 実行時間 メモリ
example_0.txt AC 6 ms 2040 KiB
example_1.txt AC 2 ms 2068 KiB
example_2.txt AC 1 ms 2008 KiB
example_3.txt AC 1 ms 2028 KiB
maxrand_0.txt AC 1 ms 2076 KiB
maxrand_1.txt AC 1 ms 2024 KiB
maxrand_2.txt AC 2 ms 2044 KiB
random_0.txt AC 1 ms 2056 KiB
random_1.txt AC 3 ms 2100 KiB
random_2.txt AC 2 ms 1940 KiB
random_3.txt AC 2 ms 2120 KiB
random_4.txt AC 1 ms 2048 KiB
random_5.txt AC 1 ms 2060 KiB
random_6.txt AC 2 ms 2124 KiB
random_7.txt AC 2 ms 2056 KiB
random_8.txt AC 1 ms 2120 KiB
random_9.txt AC 1 ms 1952 KiB
special_0.txt AC 2 ms 2056 KiB