結果

問題 No.1610 She Loves Me, She Loves Me Not, ...
ユーザー tentententen
提出日時 2022-09-29 11:34:33
言語 Java21
(openjdk 21)
結果
AC  
実行時間 143 ms / 2,000 ms
コード長 2,104 bytes
コンパイル時間 2,273 ms
コンパイル使用メモリ 75,184 KB
実行使用メモリ 54,980 KB
最終ジャッジ日時 2023-08-24 04:56:34
合計ジャッジ時間 7,262 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
49,024 KB
testcase_01 AC 47 ms
49,152 KB
testcase_02 AC 44 ms
49,168 KB
testcase_03 AC 43 ms
49,112 KB
testcase_04 AC 44 ms
49,164 KB
testcase_05 AC 141 ms
54,808 KB
testcase_06 AC 142 ms
54,980 KB
testcase_07 AC 141 ms
54,840 KB
testcase_08 AC 135 ms
54,972 KB
testcase_09 AC 143 ms
54,972 KB
testcase_10 AC 132 ms
54,880 KB
testcase_11 AC 131 ms
54,740 KB
testcase_12 AC 133 ms
54,784 KB
testcase_13 AC 140 ms
54,708 KB
testcase_14 AC 76 ms
51,240 KB
testcase_15 AC 65 ms
50,160 KB
testcase_16 AC 60 ms
50,060 KB
testcase_17 AC 60 ms
50,560 KB
testcase_18 AC 60 ms
50,360 KB
testcase_19 AC 60 ms
49,876 KB
testcase_20 AC 61 ms
50,188 KB
testcase_21 AC 59 ms
50,280 KB
testcase_22 AC 61 ms
50,904 KB
testcase_23 AC 44 ms
48,984 KB
testcase_24 AC 43 ms
49,604 KB
testcase_25 AC 43 ms
49,340 KB
testcase_26 AC 43 ms
49,156 KB
testcase_27 AC 44 ms
49,152 KB
testcase_28 AC 44 ms
49,404 KB
testcase_29 AC 46 ms
49,604 KB
testcase_30 AC 44 ms
49,320 KB
testcase_31 AC 46 ms
49,244 KB
testcase_32 AC 44 ms
49,252 KB
testcase_33 AC 44 ms
49,084 KB
testcase_34 AC 43 ms
47,908 KB
testcase_35 AC 44 ms
49,184 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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<>());
        }
        int[] counts = new int[n];
        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);
            counts[a]++;
            counts[b]++;
        }
        ArrayDeque<Integer> deq = new ArrayDeque<>();
        for (int i = 0; i < n; i++) {
            if (counts[i] == 1) {
                deq.add(i);
            }
        }
        int ans = 0;
        while (deq.size() > 0) {
            int x = deq.poll();
            if (counts[x] == 0) {
                continue;
            }
            ans++;
            for (int y : graph.get(x)) {
                counts[y]--;
                if (counts[y] == 1) {
                    deq.add(y);
                }
                graph.get(y).remove(x);
            }
        }
        if (ans % 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("");
    StringBuilder sb = new StringBuilder();
    
    public Scanner() throws Exception {
        
    }
    
    public int nextInt() throws Exception {
        return Integer.parseInt(next());
    }
    
    public long nextLong() throws Exception {
        return Long.parseLong(next());
    }
    
    public double nextDouble() throws Exception {
        return Double.parseDouble(next());
    }
    
    public String next() throws Exception {
        while (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
    
}
0