結果

問題 No.583 鉄道同好会
ユーザー sca1lsca1l
提出日時 2017-10-28 00:00:55
言語 Java21
(openjdk 21)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,561 bytes
コンパイル時間 2,083 ms
コンパイル使用メモリ 75,144 KB
実行使用メモリ 72,892 KB
最終ジャッジ日時 2023-08-14 05:22:44
合計ジャッジ時間 15,860 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 122 ms
55,608 KB
testcase_01 AC 122 ms
55,448 KB
testcase_02 AC 124 ms
55,852 KB
testcase_03 AC 122 ms
55,732 KB
testcase_04 AC 122 ms
55,416 KB
testcase_05 AC 123 ms
55,628 KB
testcase_06 AC 122 ms
56,096 KB
testcase_07 AC 122 ms
56,052 KB
testcase_08 AC 124 ms
55,812 KB
testcase_09 AC 131 ms
55,376 KB
testcase_10 AC 173 ms
56,036 KB
testcase_11 AC 774 ms
64,672 KB
testcase_12 AC 996 ms
67,244 KB
testcase_13 AC 953 ms
66,904 KB
testcase_14 AC 982 ms
66,868 KB
testcase_15 AC 1,249 ms
67,456 KB
testcase_16 AC 1,909 ms
69,428 KB
testcase_17 TLE -
testcase_18 TLE -
権限があれば一括ダウンロードができます

ソースコード

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]){
                    continue;
                }
                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(con<uni){
            System.out.println("NO");
            System.exit(0);
        }
        
        if(odd==0 || odd==2){
            System.out.println("YES");
        }else{
            System.out.println("NO");
        }
    }
}
0