結果
問題 | No.583 鉄道同好会 |
ユーザー | sca1l |
提出日時 | 2017-10-28 00:11:58 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 1,894 ms / 2,000 ms |
コード長 | 1,670 bytes |
コンパイル時間 | 2,101 ms |
コンパイル使用メモリ | 77,864 KB |
実行使用メモリ | 64,816 KB |
最終ジャッジ日時 | 2024-05-01 18:14:04 |
合計ジャッジ時間 | 15,753 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 146 ms
41,340 KB |
testcase_01 | AC | 117 ms
41,316 KB |
testcase_02 | AC | 114 ms
41,300 KB |
testcase_03 | AC | 102 ms
39,812 KB |
testcase_04 | AC | 115 ms
41,500 KB |
testcase_05 | AC | 114 ms
41,104 KB |
testcase_06 | AC | 103 ms
40,444 KB |
testcase_07 | AC | 111 ms
40,996 KB |
testcase_08 | AC | 109 ms
40,092 KB |
testcase_09 | AC | 123 ms
41,144 KB |
testcase_10 | AC | 149 ms
42,184 KB |
testcase_11 | AC | 904 ms
59,480 KB |
testcase_12 | AC | 1,205 ms
60,396 KB |
testcase_13 | AC | 1,162 ms
60,636 KB |
testcase_14 | AC | 1,175 ms
60,540 KB |
testcase_15 | AC | 1,280 ms
61,156 KB |
testcase_16 | AC | 1,803 ms
64,816 KB |
testcase_17 | AC | 1,891 ms
63,620 KB |
testcase_18 | AC | 1,894 ms
64,580 KB |
ソースコード
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); Set<Integer> set = new HashSet<Integer>(q); q = new ArrayList<Integer>(set); } 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"); } } }