結果
問題 | No.812 Change of Class |
ユーザー | phspls |
提出日時 | 2023-01-17 01:53:56 |
言語 | Rust (1.77.0 + proconio) |
結果 |
AC
|
実行時間 | 172 ms / 4,000 ms |
コード長 | 2,667 bytes |
コンパイル時間 | 15,598 ms |
コンパイル使用メモリ | 385,360 KB |
実行使用メモリ | 12,544 KB |
最終ジャッジ日時 | 2024-06-10 07:25:13 |
合計ジャッジ時間 | 18,976 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 50 ms
9,728 KB |
testcase_01 | AC | 8 ms
6,812 KB |
testcase_02 | AC | 28 ms
6,940 KB |
testcase_03 | AC | 59 ms
11,008 KB |
testcase_04 | AC | 52 ms
10,160 KB |
testcase_05 | AC | 161 ms
10,468 KB |
testcase_06 | AC | 140 ms
8,832 KB |
testcase_07 | AC | 4 ms
6,940 KB |
testcase_08 | AC | 2 ms
6,944 KB |
testcase_09 | AC | 157 ms
11,592 KB |
testcase_10 | AC | 172 ms
11,468 KB |
testcase_11 | AC | 15 ms
8,292 KB |
testcase_12 | AC | 111 ms
11,016 KB |
testcase_13 | AC | 1 ms
6,944 KB |
testcase_14 | AC | 1 ms
6,944 KB |
testcase_15 | AC | 110 ms
8,216 KB |
testcase_16 | AC | 7 ms
6,944 KB |
testcase_17 | AC | 96 ms
8,832 KB |
testcase_18 | AC | 70 ms
7,048 KB |
testcase_19 | AC | 81 ms
7,840 KB |
testcase_20 | AC | 165 ms
11,148 KB |
testcase_21 | AC | 69 ms
6,944 KB |
testcase_22 | AC | 31 ms
6,944 KB |
testcase_23 | AC | 6 ms
6,940 KB |
testcase_24 | AC | 9 ms
6,940 KB |
testcase_25 | AC | 25 ms
6,944 KB |
testcase_26 | AC | 130 ms
9,796 KB |
testcase_27 | AC | 114 ms
8,896 KB |
testcase_28 | AC | 78 ms
7,808 KB |
testcase_29 | AC | 18 ms
6,944 KB |
testcase_30 | AC | 101 ms
8,628 KB |
testcase_31 | AC | 87 ms
7,712 KB |
testcase_32 | AC | 38 ms
6,944 KB |
testcase_33 | AC | 107 ms
9,472 KB |
testcase_34 | AC | 8 ms
6,940 KB |
testcase_35 | AC | 20 ms
6,944 KB |
testcase_36 | AC | 7 ms
6,940 KB |
testcase_37 | AC | 46 ms
6,940 KB |
testcase_38 | AC | 6 ms
6,948 KB |
testcase_39 | AC | 48 ms
6,944 KB |
testcase_40 | AC | 12 ms
6,940 KB |
testcase_41 | AC | 6 ms
6,940 KB |
testcase_42 | AC | 103 ms
8,448 KB |
testcase_43 | AC | 24 ms
7,040 KB |
testcase_44 | AC | 70 ms
6,940 KB |
testcase_45 | AC | 7 ms
6,944 KB |
testcase_46 | AC | 22 ms
6,952 KB |
testcase_47 | AC | 68 ms
6,944 KB |
testcase_48 | AC | 79 ms
7,936 KB |
testcase_49 | AC | 19 ms
6,940 KB |
testcase_50 | AC | 1 ms
6,940 KB |
testcase_51 | AC | 22 ms
6,940 KB |
testcase_52 | AC | 46 ms
7,324 KB |
testcase_53 | AC | 13 ms
6,944 KB |
testcase_54 | AC | 10 ms
6,940 KB |
testcase_55 | AC | 39 ms
9,472 KB |
testcase_56 | AC | 60 ms
10,880 KB |
testcase_57 | AC | 64 ms
11,264 KB |
testcase_58 | AC | 26 ms
7,040 KB |
testcase_59 | AC | 72 ms
12,544 KB |
testcase_60 | AC | 1 ms
6,940 KB |
testcase_61 | AC | 1 ms
6,944 KB |
testcase_62 | AC | 1 ms
6,944 KB |
コンパイルメッセージ
warning: field `n` is never read --> src/main.rs:7:5 | 6 | struct UnionFind { | --------- field in this struct 7 | n: usize, | ^ | = note: `#[warn(dead_code)]` on by default
ソースコード
use std::collections::VecDeque; const INF: usize = 1usize << 60; struct UnionFind { n: usize, parents: Vec<usize>, } impl UnionFind { fn new(n: usize) -> Self { UnionFind { n: n, parents: (0..n).collect(), } } fn equiv(&mut self, a: usize, b: usize) -> bool { self.find(a) == self.find(b) } fn unite(&mut self, a: usize, b: usize) { if self.equiv(a, b) { return; } let (a, b) = (a.min(b), a.max(b)); let x = self.parents[a]; let y = self.parents[b]; self.parents[y] = self.parents[x]; } fn find(&mut self, a: usize) -> usize { if self.parents[a] == a { return a; } let p = self.find(self.parents[a]); self.parents[a] = p; p } } 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]; let mut uf = UnionFind::new(n); let mut size = vec![1usize; 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 p = temp[0]-1; let q = temp[1]-1; paths[p].push(q); paths[q].push(p); let pp = uf.find(p); let pq = uf.find(q); if pp == pq { continue; } uf.unite(pp, pq); let p = uf.find(pp); if p == pp { size[pp] += size[pq]; size[pq] = 0; } else { size[pq] += size[pp]; size[pp] = 0; } } let mut q = String::new(); std::io::stdin().read_line(&mut q).ok(); let q: usize = q.trim().parse().unwrap(); let a = (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 &a in a.iter() { let mut dists = vec![INF; n]; dists[a] = 0; let mut deque = VecDeque::new(); deque.push_back(a); while let Some(u) = deque.pop_front() { for &v in paths[u].iter() { if dists[v] < INF { continue; } dists[v] = dists[u] + 1; deque.push_back(v); } } println!("{} {}", size[uf.find(a)]-1, (*dists.iter().filter(|&&v| v < INF).max().unwrap() as f64).log2().ceil() as usize); } }