結果
問題 | No.812 Change of Class |
ユーザー | koba-e964 |
提出日時 | 2019-03-21 00:09:59 |
言語 | Rust (1.77.0 + proconio) |
結果 |
AC
|
実行時間 | 144 ms / 4,000 ms |
コード長 | 3,048 bytes |
コンパイル時間 | 12,322 ms |
コンパイル使用メモリ | 400,228 KB |
実行使用メモリ | 16,056 KB |
最終ジャッジ日時 | 2024-06-12 06:21:39 |
合計ジャッジ時間 | 17,415 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 54 ms
11,000 KB |
testcase_01 | AC | 9 ms
6,812 KB |
testcase_02 | AC | 30 ms
6,940 KB |
testcase_03 | AC | 66 ms
12,372 KB |
testcase_04 | AC | 57 ms
11,300 KB |
testcase_05 | AC | 144 ms
12,600 KB |
testcase_06 | AC | 132 ms
13,560 KB |
testcase_07 | AC | 1 ms
6,944 KB |
testcase_08 | AC | 1 ms
6,944 KB |
testcase_09 | AC | 128 ms
13,500 KB |
testcase_10 | AC | 130 ms
13,496 KB |
testcase_11 | AC | 9 ms
6,940 KB |
testcase_12 | AC | 85 ms
12,004 KB |
testcase_13 | AC | 1 ms
6,940 KB |
testcase_14 | AC | 1 ms
6,940 KB |
testcase_15 | AC | 91 ms
10,000 KB |
testcase_16 | AC | 6 ms
6,940 KB |
testcase_17 | AC | 83 ms
10,460 KB |
testcase_18 | AC | 63 ms
7,804 KB |
testcase_19 | AC | 73 ms
9,400 KB |
testcase_20 | AC | 135 ms
13,072 KB |
testcase_21 | AC | 59 ms
7,512 KB |
testcase_22 | AC | 26 ms
6,944 KB |
testcase_23 | AC | 5 ms
6,944 KB |
testcase_24 | AC | 8 ms
6,944 KB |
testcase_25 | AC | 22 ms
6,940 KB |
testcase_26 | AC | 120 ms
11,288 KB |
testcase_27 | AC | 103 ms
10,616 KB |
testcase_28 | AC | 72 ms
9,396 KB |
testcase_29 | AC | 17 ms
6,944 KB |
testcase_30 | AC | 90 ms
10,312 KB |
testcase_31 | AC | 75 ms
8,232 KB |
testcase_32 | AC | 36 ms
6,944 KB |
testcase_33 | AC | 92 ms
11,088 KB |
testcase_34 | AC | 7 ms
6,944 KB |
testcase_35 | AC | 19 ms
6,940 KB |
testcase_36 | AC | 9 ms
6,944 KB |
testcase_37 | AC | 52 ms
6,944 KB |
testcase_38 | AC | 3 ms
6,944 KB |
testcase_39 | AC | 51 ms
6,940 KB |
testcase_40 | AC | 11 ms
6,940 KB |
testcase_41 | AC | 3 ms
6,940 KB |
testcase_42 | AC | 103 ms
9,708 KB |
testcase_43 | AC | 19 ms
7,020 KB |
testcase_44 | AC | 76 ms
7,080 KB |
testcase_45 | AC | 9 ms
6,944 KB |
testcase_46 | AC | 20 ms
6,940 KB |
testcase_47 | AC | 77 ms
7,088 KB |
testcase_48 | AC | 75 ms
7,964 KB |
testcase_49 | AC | 22 ms
6,944 KB |
testcase_50 | AC | 2 ms
6,940 KB |
testcase_51 | AC | 19 ms
6,944 KB |
testcase_52 | AC | 38 ms
7,384 KB |
testcase_53 | AC | 15 ms
6,940 KB |
testcase_54 | AC | 14 ms
6,940 KB |
testcase_55 | AC | 53 ms
11,284 KB |
testcase_56 | AC | 61 ms
14,532 KB |
testcase_57 | AC | 64 ms
14,996 KB |
testcase_58 | AC | 34 ms
8,684 KB |
testcase_59 | AC | 72 ms
16,056 KB |
testcase_60 | AC | 1 ms
6,944 KB |
testcase_61 | AC | 1 ms
6,940 KB |
testcase_62 | AC | 1 ms
6,940 KB |
ソースコード
#[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(); }