結果

問題 No.583 鉄道同好会
ユーザー sca1lsca1l
提出日時 2017-10-27 23:56:34
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,556 bytes
コンパイル時間 2,669 ms
コンパイル使用メモリ 78,260 KB
実行使用メモリ 59,728 KB
最終ジャッジ日時 2024-05-01 18:04:27
合計ジャッジ時間 10,198 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 126 ms
41,424 KB
testcase_01 AC 131 ms
41,176 KB
testcase_02 AC 130 ms
41,128 KB
testcase_03 AC 124 ms
39,728 KB
testcase_04 AC 118 ms
41,288 KB
testcase_05 AC 128 ms
41,324 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 132 ms
41,248 KB
testcase_09 AC 121 ms
41,392 KB
testcase_10 AC 183 ms
42,112 KB
testcase_11 AC 507 ms
49,188 KB
testcase_12 AC 582 ms
49,856 KB
testcase_13 AC 554 ms
49,992 KB
testcase_14 AC 535 ms
49,968 KB
testcase_15 AC 615 ms
50,532 KB
testcase_16 AC 825 ms
57,532 KB
testcase_17 AC 872 ms
59,728 KB
testcase_18 AC 871 ms
59,652 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        
        int n = sc.nextInt();
        int m = sc.nextInt();
        
        int[] c = new int[n];
        ArrayList[] x = new ArrayList[n];
        for(int i=0; i<n; i++){
            x[i] = new ArrayList<Integer>();
        }
        
        int at = 0;
        for(int i=0; i<m; i++){
            int a = sc.nextInt();
            int b = sc.nextInt();
            x[a].add(b);
            x[b].add(a);
            c[a]++;
            c[b]++;
            at = a;
        }
        
        int con = 0;
        ArrayList<Integer> q = new ArrayList<Integer>();
        q.add(at);
        boolean[] ch = new boolean[n];
        while(q.size()>0){
            int now = q.remove(0);
            ch[now] = true;
            for(int i=0; i<x[now].size(); i++){
                int ne = (int)x[now].get(i);
                if(ch[ne]){
                    break;
                }
                q.add(ne);
            }
            con++;
        }
        
        int uni = 0;
        int odd = 0;
        for(int i=0; i<n; i++){
            if(c[i]%2==1){
               odd++;
            }
            if(c[i]>0){
                uni++;
            }
        }
        
        if(odd==0 || odd==2){
            if(con<uni){
                System.out.println("NO");
            }else{
                System.out.println("YES");
            }
        }else{
            System.out.println("NO");
        }
    }
}
0