結果
| 問題 | 
                            No.2202 贅沢てりたまチキン
                             | 
                    
| コンテスト | |
| ユーザー | 
                             ixTL255
                         | 
                    
| 提出日時 | 2023-02-11 18:52:08 | 
| 言語 | Rust  (1.83.0 + proconio)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 49 ms / 2,000 ms | 
| コード長 | 1,792 bytes | 
| コンパイル時間 | 10,186 ms | 
| コンパイル使用メモリ | 389,340 KB | 
| 実行使用メモリ | 8,172 KB | 
| 最終ジャッジ日時 | 2024-07-08 06:10:29 | 
| 合計ジャッジ時間 | 12,543 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge5 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 28 | 
コンパイルメッセージ
warning: method `size` is never used
  --> src/main.rs:44:8
   |
8  | impl UnionFind {
   | -------------- method in this implementation
...
44 |     fn size(&mut self, x: usize) -> usize {
   |        ^^^^
   |
   = note: `#[warn(dead_code)]` on by default
            
            ソースコード
use std::io;
struct UnionFind {
    par: Vec<usize>,
    siz: Vec<usize>,
}
impl UnionFind {
    fn new(n: usize) -> Self {
        UnionFind {
            par: (0..n).collect(),
            siz: vec![1; n],
        }
    }
    
    fn root(&mut self, x: usize) -> usize {
        if self.par[x] == x {
            return x;
        }
        self.par[x] = self.root(self.par[x]);
        self.par[x]
    }
    fn issame(&mut self, x: usize, y: usize) -> bool {
        self.root(x) == self.root(y)
    }
    fn unite(&mut self, mut parent: usize, mut child: usize) -> bool {
        parent = self.root(parent);
        child = self.root(child);
        if parent == child {
            return false;
        }
        if self.siz[parent] < self.siz[child] {
            std::mem::swap(&mut parent, &mut child);
        }
        self.par[child] = parent;
        self.siz[parent] += self.siz[child];
        true
    }
    fn size(&mut self, x: usize) -> usize {
        let root = self.root(x);
        self.siz[root]        
    }
}
fn main() {
    let mut s = String::new();
    io::stdin().read_line(&mut s).ok();
    let mut itr = s.trim().split_whitespace();
    let n: usize = itr.next().unwrap().parse().unwrap();
    let m: usize = itr.next().unwrap().parse().unwrap();
    let mut uf = UnionFind::new(2 * n);
    for _ in 0..m {
        let mut s = String::new();
        io::stdin().read_line(&mut s).ok();
        let mut itr = s.trim().split_whitespace();
        let a: usize = itr.next().unwrap().parse().unwrap();
        let b: usize = itr.next().unwrap().parse().unwrap();
        uf.unite(a - 1, b - 1 + n);
        uf.unite(b - 1, a - 1 + n);
    }
    let ans = (0..n).all(|x| uf.issame(x, x + n));
    if ans { println!("Yes"); }
    else { println!("No"); }
}
            
            
            
        
            
ixTL255