結果
| 問題 | No.1610 She Loves Me, She Loves Me Not, ... | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2022-10-24 12:07:40 | 
| 言語 | Rust (1.83.0 + proconio) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 3 ms / 2,000 ms | 
| コード長 | 1,892 bytes | 
| コンパイル時間 | 14,917 ms | 
| コンパイル使用メモリ | 377,652 KB | 
| 実行使用メモリ | 5,376 KB | 
| 最終ジャッジ日時 | 2024-07-02 15:16:09 | 
| 合計ジャッジ時間 | 16,333 ms | 
| ジャッジサーバーID (参考情報) | judge1 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 4 | 
| other | AC * 32 | 
コンパイルメッセージ
warning: unused import: `HashSet`
 --> src/main.rs:1:24
  |
1 | use std::collections::{HashSet, VecDeque};
  |                        ^^^^^^^
  |
  = note: `#[warn(unused_imports)]` on by default
            
            ソースコード
use std::collections::{HashSet, VecDeque};
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];
    for i 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 a = temp[0]-1;
        let b = temp[1]-1;
        paths[a].push((b, i));
        paths[b].push((a, i));
    }
    let mut cnt = 0usize;
    let mut deque = VecDeque::new();
    for i in 0..n {
        if paths[i].len() == 1 {
            deque.push_back((i, paths[i][0].0, paths[i][0].1));
        }
    }
    let mut checked = vec![false; m];
    while let Some((l, r, idx)) = deque.pop_front() {
        if checked[idx] { continue; }
        if paths[l].len() == 1 && paths[l][0].0 == r {
            paths[l].pop();
        } else {
            if let Some(idx) = paths[l].iter().enumerate().filter(|&(_, &j)| j.1 == idx).map(|(i, _)| i).nth(0) {
                paths[l].remove(idx);
                if paths[l].len() == 1 {
                    deque.push_back((l, paths[l][0].0, paths[l][1].1));
                }
            }
        }
        if paths[r].len() == 1 && paths[r][0].0 == l {
            paths[r].pop();
        } else {
            if let Some(idx) = paths[r].iter().enumerate().filter(|&(_, &j)| j.1 == idx).map(|(i, _)| i).nth(0) {
                paths[r].remove(idx);
                if paths[r].len() == 1 {
                    deque.push_back((r, paths[r][0].0, paths[r][0].1));
                }
            }
        }
        checked[idx] = true;
        cnt += 1;
    }
    println!("{}", if cnt % 2 == 1 { "Yes" } else { "No" });
}
            
            
            
        