結果

問題 No.2072 Anatomy
ユーザー zeronosu77108zeronosu77108
提出日時 2022-09-16 22:12:04
言語 Rust
(1.59.0)
結果
AC  
実行時間 70 ms / 2,000 ms
コード長 3,347 bytes
コンパイル時間 1,772 ms
使用メモリ 32,860 KB
最終ジャッジ日時 2023-01-11 07:18:38
合計ジャッジ時間 3,889 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
使用メモリ
testcase_00 AC 1 ms
4,904 KB
testcase_01 AC 0 ms
4,904 KB
testcase_02 AC 1 ms
6,948 KB
testcase_03 AC 1 ms
6,948 KB
testcase_04 AC 1 ms
6,948 KB
testcase_05 AC 1 ms
6,952 KB
testcase_06 AC 1 ms
4,904 KB
testcase_07 AC 1 ms
4,900 KB
testcase_08 AC 61 ms
28,848 KB
testcase_09 AC 61 ms
30,808 KB
testcase_10 AC 61 ms
29,092 KB
testcase_11 AC 64 ms
30,764 KB
testcase_12 AC 49 ms
24,012 KB
testcase_13 AC 69 ms
31,860 KB
testcase_14 AC 44 ms
20,704 KB
testcase_15 AC 38 ms
20,508 KB
testcase_16 AC 69 ms
31,772 KB
testcase_17 AC 65 ms
32,012 KB
testcase_18 AC 33 ms
17,508 KB
testcase_19 AC 69 ms
32,704 KB
testcase_20 AC 68 ms
32,860 KB
testcase_21 AC 63 ms
31,784 KB
testcase_22 AC 68 ms
32,592 KB
testcase_23 AC 66 ms
31,896 KB
testcase_24 AC 64 ms
32,232 KB
testcase_25 AC 70 ms
32,380 KB
testcase_26 AC 1 ms
6,952 KB
testcase_27 AC 67 ms
32,700 KB
testcase_28 AC 61 ms
32,660 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
warning: unused variable: `l`
  --> Main.rs:15:13
   |
15 |         let l = r ^ a ^ b;
   |             ^ help: if this is intentional, prefix it with an underscore: `_l`
   |
   = note: `#[warn(unused_variables)]` on by default

warning: 1 warning emitted

ソースコード

diff #


fn main() {
    let mut sc = Scanner::new();
    let n = sc.usize();
    let m = sc.usize();

    let mut ans = vec![0; n];
    let mut uni = UnionFind::new(n);
    for &(a, b) in sc.edges(m).iter().rev() {
        let a = uni.root(a); let b = uni.root(b);
        uni.merge(a,b);

        let r = uni.root(a);
        let l = r ^ a ^ b;

        ans[r] = ans[a].max(ans[b]) + 1;
    }

    println!("{}", ans.iter().max().unwrap());
}

struct UnionFind { per : Vec<Option<usize>>, size : Vec<usize> } #[allow(dead_code)] impl UnionFind { fn new (n : usize) -> Self { Self { per : vec![None; n+1], size: vec![1; n+1]} } fn root (&mut self, x : usize) -> usize { if let Some(y) = self.per[x] { let res = self.root(y); self.per[x] = Some(res); res } else { x } } fn merge(&mut self, mut x : usize, mut y : usize) -> bool { x = self.root(x); y = self.root(y); if x == y { return false; } if self.size[x] < self.size[y] { std::mem::swap(&mut x, &mut y); } self.per[y] = Some(x); self.size[x] += self.size[y]; true } fn same(&mut self, x : usize, y : usize) -> bool { self.root(x) == self.root(y) } fn size(&mut self, x : usize) -> usize { let x = self.root(x); self.size[x] } }


struct Scanner { s : std::collections::VecDeque<String> } #[allow(unused)] impl Scanner { fn new() -> Self { use std::io::Read; let mut s = String::new(); std::io::stdin().read_to_string(&mut s).unwrap(); Self { s : s.split_whitespace().map(|s| s.to_string()).collect() } } fn reload(&mut self) -> () { use std::io::Read; let mut s = String::new(); std::io::stdin().read_to_string(&mut s).unwrap(); self.s = s.split_whitespace().map(|s| s.to_string()).collect(); } fn usize(&mut self) -> usize { self.input() } fn usize1(&mut self) -> usize { self.input::<usize>() - 1 } fn isize(&mut self) -> isize { self.input() } fn i32(&mut self) -> i32 { self.input() } fn i64(&mut self) -> i64 { self.input() } fn i128(&mut self) -> i128 { self.input() } fn u8(&mut self) -> u8 { self.input() } fn u32(&mut self) -> u32 { self.input() } fn u64(&mut self) -> u64 { self.input() } fn u128(&mut self) -> u128 { self.input() } fn edge(&mut self) -> (usize, usize) { (self.usize1(), self.usize1()) } fn edges(&mut self, m : usize) -> Vec<(usize, usize)> { let mut e = Vec::with_capacity(m); for _ in 0..m { e.push(self.edge()); } e } fn wedge<T:std::str::FromStr>(&mut self) -> (usize, usize, T) { (self.usize1(), self.usize1(), self.input()) } fn wedges<T:std::str::FromStr>(&mut self, m : usize) -> Vec<(usize, usize, T)> { let mut e = Vec::with_capacity(m); for _ in 0..m { e.push(self.wedge()); } e } fn input<T>(&mut self) -> T where T: std::str::FromStr { if self.s.is_empty() { self.reload(); } if let Some(head) = self.s.pop_front() { head.parse::<T>().ok().unwrap() } else { panic!() } } fn tuple<T, U>(&mut self) -> (T, U) where T: std::str::FromStr, U: std::str::FromStr { (self.input(), self.input()) } fn vec<T>(&mut self, n: usize) -> Vec<T> where T: std::str::FromStr { if self.s.is_empty() { self.reload(); } self.s.drain(..n).map(|s| s.parse::<T>().ok().unwrap() ).collect::<Vec<T>>() } fn nvec<T>(&mut self) -> Vec<T> where T: std::str::FromStr { let n : usize = self.input(); self.vec(n) } fn chars(&mut self) -> Vec<char> { let s : String = self.input(); s.chars().collect() } fn bytes(&mut self) -> Vec<u8> { let s : String = self.input(); s.bytes().collect() } }
0