結果

問題 No.2072 Anatomy
ユーザー 👑 zeronosu77108zeronosu77108
提出日時 2022-09-16 22:12:04
言語 Rust
(1.77.0)
結果
AC  
実行時間 78 ms / 2,000 ms
コード長 3,347 bytes
コンパイル時間 991 ms
コンパイル使用メモリ 153,628 KB
実行使用メモリ 34,080 KB
最終ジャッジ日時 2023-08-23 15:47:52
合計ジャッジ時間 4,371 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 70 ms
28,992 KB
testcase_09 AC 67 ms
30,796 KB
testcase_10 AC 71 ms
29,560 KB
testcase_11 AC 73 ms
31,032 KB
testcase_12 AC 55 ms
24,124 KB
testcase_13 AC 77 ms
31,544 KB
testcase_14 AC 49 ms
20,956 KB
testcase_15 AC 45 ms
20,408 KB
testcase_16 AC 78 ms
33,168 KB
testcase_17 AC 75 ms
32,992 KB
testcase_18 AC 38 ms
17,636 KB
testcase_19 AC 76 ms
33,420 KB
testcase_20 AC 77 ms
32,288 KB
testcase_21 AC 74 ms
32,316 KB
testcase_22 AC 78 ms
32,752 KB
testcase_23 AC 74 ms
32,688 KB
testcase_24 AC 73 ms
33,024 KB
testcase_25 AC 75 ms
32,520 KB
testcase_26 AC 1 ms
4,380 KB
testcase_27 AC 75 ms
32,964 KB
testcase_28 AC 68 ms
34,080 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