結果

問題 No.812 Change of Class
ユーザー phsplsphspls
提出日時 2023-01-02 17:41:48
言語 Rust
(1.77.0)
結果
AC  
実行時間 135 ms / 4,000 ms
コード長 1,751 bytes
コンパイル時間 15,356 ms
コンパイル使用メモリ 377,440 KB
実行使用メモリ 10,368 KB
最終ジャッジ日時 2024-05-05 06:32:40
合計ジャッジ時間 20,935 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
7,936 KB
testcase_01 AC 7 ms
5,376 KB
testcase_02 AC 23 ms
5,504 KB
testcase_03 AC 48 ms
8,960 KB
testcase_04 AC 44 ms
8,064 KB
testcase_05 AC 135 ms
8,576 KB
testcase_06 AC 107 ms
7,424 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 1 ms
5,376 KB
testcase_09 AC 114 ms
9,088 KB
testcase_10 AC 117 ms
9,216 KB
testcase_11 AC 7 ms
6,016 KB
testcase_12 AC 75 ms
8,704 KB
testcase_13 AC 1 ms
5,376 KB
testcase_14 AC 1 ms
5,376 KB
testcase_15 AC 78 ms
6,944 KB
testcase_16 AC 6 ms
5,376 KB
testcase_17 AC 71 ms
7,168 KB
testcase_18 AC 53 ms
6,016 KB
testcase_19 AC 62 ms
6,656 KB
testcase_20 AC 127 ms
9,088 KB
testcase_21 AC 54 ms
5,760 KB
testcase_22 AC 24 ms
5,376 KB
testcase_23 AC 5 ms
5,376 KB
testcase_24 AC 7 ms
5,376 KB
testcase_25 AC 20 ms
5,376 KB
testcase_26 AC 98 ms
7,936 KB
testcase_27 AC 87 ms
7,296 KB
testcase_28 AC 62 ms
6,528 KB
testcase_29 AC 15 ms
5,376 KB
testcase_30 AC 81 ms
7,040 KB
testcase_31 AC 69 ms
6,400 KB
testcase_32 AC 29 ms
5,376 KB
testcase_33 AC 81 ms
7,680 KB
testcase_34 AC 7 ms
5,376 KB
testcase_35 AC 15 ms
5,376 KB
testcase_36 AC 6 ms
5,376 KB
testcase_37 AC 38 ms
5,376 KB
testcase_38 AC 3 ms
5,376 KB
testcase_39 AC 40 ms
5,376 KB
testcase_40 AC 10 ms
5,376 KB
testcase_41 AC 3 ms
5,376 KB
testcase_42 AC 81 ms
6,912 KB
testcase_43 AC 14 ms
5,760 KB
testcase_44 AC 55 ms
5,888 KB
testcase_45 AC 6 ms
5,376 KB
testcase_46 AC 13 ms
5,632 KB
testcase_47 AC 54 ms
5,760 KB
testcase_48 AC 58 ms
6,528 KB
testcase_49 AC 15 ms
5,376 KB
testcase_50 AC 2 ms
5,376 KB
testcase_51 AC 17 ms
5,376 KB
testcase_52 AC 32 ms
6,144 KB
testcase_53 AC 11 ms
5,376 KB
testcase_54 AC 8 ms
5,376 KB
testcase_55 AC 33 ms
8,064 KB
testcase_56 AC 39 ms
9,216 KB
testcase_57 AC 41 ms
9,600 KB
testcase_58 AC 23 ms
6,144 KB
testcase_59 AC 48 ms
10,368 KB
testcase_60 AC 1 ms
5,376 KB
testcase_61 AC 1 ms
5,376 KB
testcase_62 AC 1 ms
5,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