結果
| 問題 | No.1610 She Loves Me, She Loves Me Not, ... | 
| コンテスト | |
| ユーザー |  tenten | 
| 提出日時 | 2021-07-26 14:19:24 | 
| 言語 | Java (openjdk 23) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 152 ms / 2,000 ms | 
| コード長 | 1,846 bytes | 
| コンパイル時間 | 2,314 ms | 
| コンパイル使用メモリ | 78,504 KB | 
| 実行使用メモリ | 42,028 KB | 
| 最終ジャッジ日時 | 2024-07-22 04:22:07 | 
| 合計ジャッジ時間 | 6,677 ms | 
| ジャッジサーバーID (参考情報) | judge5 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 4 | 
| other | AC * 32 | 
ソースコード
import java.io.*;
import java.util.*;
public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        int n = sc.nextInt();
        int m = sc.nextInt();
        ArrayList<HashSet<Integer>> graph = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            graph.add(new HashSet<>());
        }
        for (int i = 0; i < m; i++) {
            int a = sc.nextInt() - 1;
            int b = sc.nextInt() - 1;
            graph.get(a).add(b);
            graph.get(b).add(a);
        }
        ArrayDeque<Integer> deq = new ArrayDeque<>();
        for (int i = 0; i < n; i++) {
            if (graph.get(i).size() == 1) {
                deq.add(i);
            }
        }
        int count = 0;
        while (deq.size() > 0) {
            int x = deq.poll();
            if (graph.get(x).size() == 0) {
                continue;
            }
            count++;
            int y = graph.get(x).iterator().next();
            graph.get(y).remove(x);
            if (graph.get(y).size() == 1) {
                deq.add(y);
            }
        }
        if (count % 2 == 1) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }
}
class Scanner {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st = new StringTokenizer("");
    
    public Scanner() throws Exception {
        
    }
    
    public int nextInt() throws Exception {
        return Integer.parseInt(next());
    }
    
    public long nextLong() throws Exception {
        return Long.parseLong(next());
    }
    
    public String next() throws Exception {
        if (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
}
            
            
            
        