結果

問題 No.806 木を道に
ユーザー iwotiwot
提出日時 2019-08-13 23:42:14
言語 Rust
(1.77.0)
結果
AC  
実行時間 28 ms / 2,000 ms
コード長 943 bytes
コンパイル時間 1,754 ms
コンパイル使用メモリ 186,184 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-19 17:18:11
合計ジャッジ時間 2,874 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 1 ms
4,348 KB
testcase_02 AC 1 ms
4,348 KB
testcase_03 AC 1 ms
4,348 KB
testcase_04 AC 1 ms
4,348 KB
testcase_05 AC 1 ms
4,348 KB
testcase_06 AC 1 ms
4,348 KB
testcase_07 AC 1 ms
4,348 KB
testcase_08 AC 1 ms
4,348 KB
testcase_09 AC 1 ms
4,348 KB
testcase_10 AC 7 ms
4,348 KB
testcase_11 AC 6 ms
4,348 KB
testcase_12 AC 25 ms
4,348 KB
testcase_13 AC 19 ms
4,348 KB
testcase_14 AC 23 ms
4,348 KB
testcase_15 AC 24 ms
4,348 KB
testcase_16 AC 10 ms
4,348 KB
testcase_17 AC 22 ms
4,348 KB
testcase_18 AC 3 ms
4,348 KB
testcase_19 AC 7 ms
4,348 KB
testcase_20 AC 22 ms
4,348 KB
testcase_21 AC 12 ms
4,348 KB
testcase_22 AC 27 ms
4,348 KB
testcase_23 AC 28 ms
4,348 KB
testcase_24 AC 13 ms
4,348 KB
testcase_25 AC 21 ms
4,348 KB
testcase_26 AC 9 ms
4,348 KB
testcase_27 AC 25 ms
4,348 KB
testcase_28 AC 1 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

use std::collections::HashMap;

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

fn main() {
    let peak_max: usize = read();

    let mut peaks = HashMap::new();
    for _i in 0..peak_max-1 {
        let input: Vec<u32> = read_vec();
        {
            let e = peaks.entry(input[0]).or_insert(0);
            *e += 1;
        }
        {
            let e = peaks.entry(input[1]).or_insert(0);
            *e += 1;
        }
    }

    let mut operation = 0;
    for (_peak, count) in &peaks {
        if *count > 2 {
            operation += *count - 2;
        }
    }

    println!("{}", operation);
}
0