結果

問題 No.812 Change of Class
ユーザー koba-e964koba-e964
提出日時 2019-03-21 00:09:59
言語 Rust
(1.77.0)
結果
AC  
実行時間 208 ms / 4,000 ms
コード長 3,048 bytes
コンパイル時間 3,721 ms
コンパイル使用メモリ 172,228 KB
実行使用メモリ 15,020 KB
最終ジャッジ日時 2023-09-03 00:31:37
合計ジャッジ時間 11,170 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 73 ms
10,136 KB
testcase_01 AC 11 ms
4,380 KB
testcase_02 AC 39 ms
5,952 KB
testcase_03 AC 84 ms
11,428 KB
testcase_04 AC 75 ms
10,420 KB
testcase_05 AC 208 ms
11,548 KB
testcase_06 AC 178 ms
12,564 KB
testcase_07 AC 2 ms
4,384 KB
testcase_08 AC 1 ms
4,384 KB
testcase_09 AC 188 ms
12,360 KB
testcase_10 AC 192 ms
12,356 KB
testcase_11 AC 14 ms
5,504 KB
testcase_12 AC 111 ms
11,272 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 105 ms
9,080 KB
testcase_16 AC 7 ms
4,380 KB
testcase_17 AC 98 ms
9,544 KB
testcase_18 AC 74 ms
6,736 KB
testcase_19 AC 88 ms
8,556 KB
testcase_20 AC 182 ms
12,348 KB
testcase_21 AC 72 ms
6,524 KB
testcase_22 AC 32 ms
4,376 KB
testcase_23 AC 6 ms
4,380 KB
testcase_24 AC 9 ms
4,380 KB
testcase_25 AC 26 ms
4,380 KB
testcase_26 AC 141 ms
10,388 KB
testcase_27 AC 116 ms
9,500 KB
testcase_28 AC 83 ms
8,492 KB
testcase_29 AC 18 ms
4,380 KB
testcase_30 AC 104 ms
9,148 KB
testcase_31 AC 90 ms
7,184 KB
testcase_32 AC 42 ms
4,604 KB
testcase_33 AC 113 ms
10,140 KB
testcase_34 AC 8 ms
4,380 KB
testcase_35 AC 22 ms
4,376 KB
testcase_36 AC 10 ms
4,380 KB
testcase_37 AC 59 ms
4,988 KB
testcase_38 AC 5 ms
4,380 KB
testcase_39 AC 59 ms
4,920 KB
testcase_40 AC 14 ms
4,376 KB
testcase_41 AC 3 ms
4,380 KB
testcase_42 AC 120 ms
8,828 KB
testcase_43 AC 26 ms
5,988 KB
testcase_44 AC 88 ms
6,188 KB
testcase_45 AC 11 ms
4,380 KB
testcase_46 AC 27 ms
5,940 KB
testcase_47 AC 85 ms
6,264 KB
testcase_48 AC 88 ms
7,088 KB
testcase_49 AC 26 ms
4,380 KB
testcase_50 AC 2 ms
4,380 KB
testcase_51 AC 23 ms
4,380 KB
testcase_52 AC 48 ms
6,468 KB
testcase_53 AC 17 ms
4,380 KB
testcase_54 AC 15 ms
4,376 KB
testcase_55 AC 62 ms
10,492 KB
testcase_56 AC 74 ms
13,580 KB
testcase_57 AC 77 ms
13,856 KB
testcase_58 AC 40 ms
7,772 KB
testcase_59 AC 87 ms
15,020 KB
testcase_60 AC 1 ms
4,380 KB
testcase_61 AC 1 ms
4,380 KB
testcase_62 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
use std::io::{Write, BufWriter};
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, [ $t:tt ]) => {{
        let len = read_value!($next, usize);
        (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    }};

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn solve() {
    let out = std::io::stdout();
    let mut out = BufWriter::new(out.lock());
    macro_rules! puts {
        ($($format:tt)*) => (write!(out,$($format)*).unwrap());
    }
    input! {
        n: usize,
        pq: [(usize1, usize1)],
        a: [usize1],
    }
    // Verification
    assert!(1 <= n && n <= 100000);
    assert!(pq.len() <= 100000);
    let mut seen = HashSet::new();
    for &(p, q) in &pq {
        assert!(p < q);
        assert_eq!(seen.get(&(p, q)), None);
        seen.insert((p, q));
    }

    // solve, O(q (m + n))
    let mut g = vec![vec![]; n];
    for &(p, q) in &pq {
        g[p].push(q);
        g[q].push(p);
    }
    for &a in &a {
        let mut que = VecDeque::new();
        que.push_back((a, 0));
        let mut vis = vec![false; n];
        let mut ma = 0;
        let mut count = 0;
        while let Some((v, d)) = que.pop_front() {
            if vis[v] { continue; }
            vis[v] = true;
            count += 1;
            ma = max(ma, d);
            for &w in &g[v] {
                que.push_back((w, d + 1));
            }
            
        }
        let mut turn = 0;
        while ma > 1 << turn {
            turn += 1;
        }
        puts!("{} {}\n", count - 1, turn);
    }
}

fn main() {
    // In order to avoid potential stack overflow, spawn a new thread.
    let stack_size = 104_857_600; // 100 MB
    let thd = std::thread::Builder::new().stack_size(stack_size);
    thd.spawn(|| solve()).unwrap().join().unwrap();
}
0