結果

問題 No.812 Change of Class
ユーザー phsplsphspls
提出日時 2023-01-02 17:41:48
言語 Rust
(1.77.0)
結果
AC  
実行時間 139 ms / 4,000 ms
コード長 1,751 bytes
コンパイル時間 3,231 ms
コンパイル使用メモリ 146,620 KB
実行使用メモリ 10,364 KB
最終ジャッジ日時 2023-08-17 23:44:18
合計ジャッジ時間 11,455 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 44 ms
7,708 KB
testcase_01 AC 8 ms
4,376 KB
testcase_02 AC 25 ms
5,320 KB
testcase_03 AC 52 ms
9,148 KB
testcase_04 AC 47 ms
7,956 KB
testcase_05 AC 137 ms
8,524 KB
testcase_06 AC 109 ms
7,256 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 128 ms
9,296 KB
testcase_10 AC 135 ms
9,296 KB
testcase_11 AC 10 ms
6,012 KB
testcase_12 AC 79 ms
8,836 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 82 ms
6,932 KB
testcase_16 AC 6 ms
4,376 KB
testcase_17 AC 79 ms
7,280 KB
testcase_18 AC 57 ms
5,964 KB
testcase_19 AC 66 ms
6,540 KB
testcase_20 AC 139 ms
9,180 KB
testcase_21 AC 56 ms
5,780 KB
testcase_22 AC 25 ms
4,376 KB
testcase_23 AC 5 ms
4,380 KB
testcase_24 AC 8 ms
4,376 KB
testcase_25 AC 20 ms
4,380 KB
testcase_26 AC 104 ms
8,152 KB
testcase_27 AC 89 ms
7,452 KB
testcase_28 AC 61 ms
6,508 KB
testcase_29 AC 14 ms
4,376 KB
testcase_30 AC 80 ms
7,172 KB
testcase_31 AC 68 ms
6,408 KB
testcase_32 AC 31 ms
4,584 KB
testcase_33 AC 88 ms
7,828 KB
testcase_34 AC 7 ms
4,376 KB
testcase_35 AC 16 ms
4,380 KB
testcase_36 AC 7 ms
4,376 KB
testcase_37 AC 39 ms
4,904 KB
testcase_38 AC 5 ms
4,380 KB
testcase_39 AC 43 ms
4,904 KB
testcase_40 AC 11 ms
4,380 KB
testcase_41 AC 3 ms
4,376 KB
testcase_42 AC 84 ms
6,952 KB
testcase_43 AC 18 ms
5,812 KB
testcase_44 AC 59 ms
5,852 KB
testcase_45 AC 6 ms
4,380 KB
testcase_46 AC 19 ms
5,356 KB
testcase_47 AC 59 ms
5,864 KB
testcase_48 AC 65 ms
6,652 KB
testcase_49 AC 17 ms
4,380 KB
testcase_50 AC 2 ms
4,380 KB
testcase_51 AC 17 ms
4,380 KB
testcase_52 AC 36 ms
5,900 KB
testcase_53 AC 12 ms
4,376 KB
testcase_54 AC 9 ms
4,380 KB
testcase_55 AC 35 ms
8,020 KB
testcase_56 AC 42 ms
8,988 KB
testcase_57 AC 44 ms
9,332 KB
testcase_58 AC 24 ms
5,956 KB
testcase_59 AC 48 ms
10,364 KB
testcase_60 AC 1 ms
4,376 KB
testcase_61 AC 1 ms
4,380 KB
testcase_62 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

use std::collections::VecDeque;


fn main() {
    let mut nm = String::new();
    std::io::stdin().read_line(&mut nm).ok();
    let nm: Vec<usize> = nm.trim().split_whitespace().map(|s| s.parse().unwrap()).collect();
    let n = nm[0];
    let m = nm[1];
    let mut paths = vec![vec![]; n];
    for _ in 0..m {
        let mut temp = String::new();
        std::io::stdin().read_line(&mut temp).ok();
        let temp: Vec<usize> = temp.trim().split_whitespace().map(|s| s.parse().unwrap()).collect();
        let u = temp[0]-1;
        let v = temp[1]-1;
        paths[u].push(v);
        paths[v].push(u);
    }
    let mut q = String::new();
    std::io::stdin().read_line(&mut q).ok();
    let q: usize = q.trim().parse().unwrap();
    let queries = (0..q).map(|_| {
            let mut temp = String::new();
            std::io::stdin().read_line(&mut temp).ok();
            let temp: usize = temp.trim().parse().unwrap();
            temp-1
        })
        .collect::<Vec<_>>();

    for &i in queries.iter() {
        let mut checked = vec![false; n];
        checked[i] = true;
        let mut dist = 0usize;
        let mut deque = VecDeque::new(); 
        deque.push_back(i);
        loop {
            let limit = deque.len();
            for _ in 0..limit {
                let u = deque.pop_front().unwrap();
                for &v in paths[u].iter() {
                    if checked[v] { continue; }
                    checked[v] = true;
                    deque.push_back(v);
                }
            }
            if deque.is_empty() {
                break;
            }
            dist += 1;
        }
        println!("{} {}", checked.iter().filter(|&&v| v).count() - 1, (dist as f64).log2().ceil() as usize);
    }
}
0