結果

問題 No.2888 Mamehinata
ユーザー naut3naut3
提出日時 2024-09-13 21:51:02
言語 Rust
(1.77.0)
結果
AC  
実行時間 131 ms / 2,000 ms
コード長 1,631 bytes
コンパイル時間 13,681 ms
コンパイル使用メモリ 382,976 KB
実行使用メモリ 22,420 KB
最終ジャッジ日時 2024-09-13 21:51:39
合計ジャッジ時間 19,247 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,816 KB
testcase_01 AC 1 ms
6,812 KB
testcase_02 AC 1 ms
6,812 KB
testcase_03 AC 1 ms
6,940 KB
testcase_04 AC 1 ms
6,940 KB
testcase_05 AC 1 ms
6,940 KB
testcase_06 AC 1 ms
6,944 KB
testcase_07 AC 1 ms
6,944 KB
testcase_08 AC 1 ms
6,940 KB
testcase_09 AC 1 ms
6,940 KB
testcase_10 AC 1 ms
6,944 KB
testcase_11 AC 1 ms
6,940 KB
testcase_12 AC 1 ms
6,940 KB
testcase_13 AC 14 ms
6,944 KB
testcase_14 AC 44 ms
8,352 KB
testcase_15 AC 52 ms
15,236 KB
testcase_16 AC 88 ms
17,048 KB
testcase_17 AC 25 ms
11,436 KB
testcase_18 AC 28 ms
9,728 KB
testcase_19 AC 88 ms
17,792 KB
testcase_20 AC 66 ms
15,272 KB
testcase_21 AC 65 ms
15,276 KB
testcase_22 AC 41 ms
13,312 KB
testcase_23 AC 57 ms
16,524 KB
testcase_24 AC 92 ms
18,572 KB
testcase_25 AC 66 ms
17,056 KB
testcase_26 AC 74 ms
17,680 KB
testcase_27 AC 60 ms
16,236 KB
testcase_28 AC 13 ms
6,944 KB
testcase_29 AC 32 ms
8,832 KB
testcase_30 AC 100 ms
19,244 KB
testcase_31 AC 86 ms
16,284 KB
testcase_32 AC 52 ms
11,904 KB
testcase_33 AC 73 ms
15,208 KB
testcase_34 AC 57 ms
13,120 KB
testcase_35 AC 47 ms
11,648 KB
testcase_36 AC 123 ms
20,832 KB
testcase_37 AC 129 ms
21,156 KB
testcase_38 AC 26 ms
7,296 KB
testcase_39 AC 127 ms
17,516 KB
testcase_40 AC 131 ms
20,900 KB
testcase_41 AC 15 ms
6,940 KB
testcase_42 AC 102 ms
18,224 KB
testcase_43 AC 73 ms
17,876 KB
testcase_44 AC 85 ms
20,040 KB
testcase_45 AC 104 ms
22,420 KB
testcase_46 AC 10 ms
6,940 KB
testcase_47 AC 77 ms
19,628 KB
testcase_48 AC 53 ms
15,188 KB
testcase_49 AC 6 ms
6,944 KB
testcase_50 AC 18 ms
10,952 KB
testcase_51 AC 3 ms
6,940 KB
testcase_52 AC 2 ms
6,944 KB
testcase_53 AC 4 ms
6,940 KB
testcase_54 AC 1 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#![allow(non_snake_case)]
#[allow(unused_imports)]
use proconio::{fastout, input, marker::*};

#[fastout]
fn main() {
    input! {
        N: usize, M: usize,
        edges: [(Usize1, Usize1); M],
    }

    let dist = {
        let mut graph = vec![vec![]; N];

        for (u, v) in edges {
            graph[u].push(v);
            graph[v].push(u);
        }

        let mut seen = vec![false; N];
        let mut dist = vec![usize::MAX; N];
        let mut q = std::collections::VecDeque::new();

        q.push_back(0);
        seen[0] = true;
        dist[0] = 0;

        while let Some(u) = q.pop_front() {
            for &v in graph[u].iter() {
                if seen[v] {
                    continue;
                }

                q.push_back(v);
                seen[v] = true;
                dist[v] = dist[u] + 1;
            }
        }

        dist
    };

    let mut isok = false;

    for i in 1..N {
        if dist[i] != usize::MAX {
            isok = true;
        }
    }

    let mut cnt = vec![0u32; N + 1];

    if !isok {
        println!(
            "{}",
            cnt[1..]
                .iter()
                .map(|x| x.to_string())
                .collect::<Vec<_>>()
                .join("\n")
        );
        return;
    }

    for i in 0..N {
        if dist[i] == usize::MAX {
            continue;
        }
        cnt[dist[i]] += 1;
    }

    for i in 0..=N - 2 {
        cnt[i + 2] += cnt[i];
    }

    println!(
        "{}",
        cnt[1..]
            .iter()
            .map(|x| x.to_string())
            .collect::<Vec<_>>()
            .join("\n")
    );
}
0