結果

問題 No.2888 Mamehinata
ユーザー atcoder8atcoder8
提出日時 2024-09-13 22:06:24
言語 Rust
(1.77.0)
結果
AC  
実行時間 375 ms / 2,000 ms
コード長 1,053 bytes
コンパイル時間 13,616 ms
コンパイル使用メモリ 393,616 KB
実行使用メモリ 29,532 KB
最終ジャッジ日時 2024-09-13 22:06:52
合計ジャッジ時間 24,745 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 1 ms
5,248 KB
testcase_02 AC 1 ms
5,248 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 1 ms
5,376 KB
testcase_08 AC 1 ms
5,376 KB
testcase_09 AC 1 ms
5,376 KB
testcase_10 AC 1 ms
5,376 KB
testcase_11 AC 1 ms
5,376 KB
testcase_12 AC 1 ms
5,376 KB
testcase_13 AC 23 ms
9,600 KB
testcase_14 AC 126 ms
7,424 KB
testcase_15 AC 174 ms
15,924 KB
testcase_16 AC 311 ms
22,272 KB
testcase_17 AC 186 ms
8,224 KB
testcase_18 AC 54 ms
14,464 KB
testcase_19 AC 277 ms
23,708 KB
testcase_20 AC 222 ms
20,576 KB
testcase_21 AC 237 ms
20,224 KB
testcase_22 AC 216 ms
11,792 KB
testcase_23 AC 279 ms
15,488 KB
testcase_24 AC 320 ms
23,040 KB
testcase_25 AC 324 ms
18,232 KB
testcase_26 AC 305 ms
20,864 KB
testcase_27 AC 279 ms
12,672 KB
testcase_28 AC 47 ms
5,376 KB
testcase_29 AC 118 ms
10,624 KB
testcase_30 AC 320 ms
23,296 KB
testcase_31 AC 244 ms
19,840 KB
testcase_32 AC 171 ms
14,336 KB
testcase_33 AC 236 ms
18,400 KB
testcase_34 AC 198 ms
15,872 KB
testcase_35 AC 167 ms
13,952 KB
testcase_36 AC 333 ms
25,344 KB
testcase_37 AC 339 ms
25,904 KB
testcase_38 AC 94 ms
8,704 KB
testcase_39 AC 274 ms
21,312 KB
testcase_40 AC 375 ms
25,412 KB
testcase_41 AC 58 ms
6,272 KB
testcase_42 AC 289 ms
21,888 KB
testcase_43 AC 250 ms
23,936 KB
testcase_44 AC 294 ms
26,456 KB
testcase_45 AC 320 ms
29,532 KB
testcase_46 AC 42 ms
5,632 KB
testcase_47 AC 275 ms
25,856 KB
testcase_48 AC 181 ms
22,204 KB
testcase_49 AC 8 ms
6,144 KB
testcase_50 AC 25 ms
16,384 KB
testcase_51 AC 2 ms
5,376 KB
testcase_52 AC 1 ms
5,376 KB
testcase_53 AC 4 ms
5,376 KB
testcase_54 AC 1 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

use std::collections::VecDeque;

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

fn main() {
    input! {
        (n, m): (usize, usize),
        uv: [(Usize1, Usize1); m],
    }

    let mut graph = vec![vec![]; n];
    for &(u, v) in &uv {
        graph[u].push(v);
        graph[v].push(u);
    }

    let mut dists = vec![None; n];
    let mut queue = VecDeque::from([(0, 0)]);
    while let Some((cur, dist)) = queue.pop_front() {
        if dists[cur].is_some() {
            continue;
        }

        dists[cur] = Some(dist);

        queue.extend(graph[cur].iter().map(|&adj| (adj, dist + 1)));
    }

    let mut counts = vec![0_usize; n + 3];
    for &dist in &dists {
        if let Some(dist) = dist {
            counts[dist] += 1;
        }
    }

    for i in 2..=n + 2 {
        counts[i] += counts[i - 2];
    }

    if dists.iter().filter(|dist| dist.is_some()).count() == 1 {
        for _ in 0..n {
            println!("0");
        }
    } else {
        for elem in &counts[1..=n] {
            println!("{}", elem);
        }
    }
}
0