結果
問題 | No.583 鉄道同好会 |
ユーザー | 夕叢霧香(ゆうむらきりか) |
提出日時 | 2017-10-27 23:07:53 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 872 ms / 2,000 ms |
コード長 | 1,374 bytes |
コンパイル時間 | 2,072 ms |
コンパイル使用メモリ | 74,708 KB |
実行使用メモリ | 70,804 KB |
最終ジャッジ日時 | 2023-08-14 04:47:30 |
合計ジャッジ時間 | 9,585 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge12 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 124 ms
56,208 KB |
testcase_01 | AC | 123 ms
55,860 KB |
testcase_02 | AC | 126 ms
55,392 KB |
testcase_03 | AC | 124 ms
55,812 KB |
testcase_04 | AC | 126 ms
55,784 KB |
testcase_05 | AC | 125 ms
55,920 KB |
testcase_06 | AC | 125 ms
55,664 KB |
testcase_07 | AC | 125 ms
55,764 KB |
testcase_08 | AC | 127 ms
56,040 KB |
testcase_09 | AC | 131 ms
55,964 KB |
testcase_10 | AC | 161 ms
56,260 KB |
testcase_11 | AC | 424 ms
60,764 KB |
testcase_12 | AC | 496 ms
62,620 KB |
testcase_13 | AC | 487 ms
62,928 KB |
testcase_14 | AC | 515 ms
62,784 KB |
testcase_15 | AC | 571 ms
62,712 KB |
testcase_16 | AC | 736 ms
69,200 KB |
testcase_17 | AC | 815 ms
70,804 KB |
testcase_18 | AC | 872 ms
70,556 KB |
ソースコード
import java.util.*; class Main { ArrayList<Integer>[] graph; @SuppressWarnings("unchecked") Main() { Scanner scan = new Scanner(System.in); int n = scan.nextInt(); this.graph = new ArrayList[n]; for (int i = 0; i < n; ++i) { this.graph[i] = new ArrayList(); } int m = scan.nextInt(); for (int i = 0; i < m; ++i) { int sa = scan.nextInt(); int sb = scan.nextInt(); this.graph[sa].add(sb); this.graph[sb].add(sa); } int numberOfOddVertices = 0; for (int i = 0; i < n; ++i) { if (graph[i].size() % 2 != 0) { numberOfOddVertices += 1; } } if (numberOfOddVertices > 2) { System.out.println("NO"); return; } // Henga renketu ka douka siraberu int start = 0; for (int i = 0; i < n; ++i) { if (graph[i].size() >= 1) { start = i; break; } } boolean[] visited = new boolean[n]; Queue<Integer> queue = new ArrayDeque(); queue.add(start); while (queue.size() >= 1) { int vertex = queue.poll(); if (visited[vertex]) { continue; } visited[vertex] = true; for (int target: this.graph[vertex]) { queue.add(target); } } for (int i = 0; i < n; ++i) { if (graph[i].size() >= 1 && !visited[i]) { System.out.println("NO"); return; } } System.out.println("YES"); } public static void main(String[] args) { new Main(); } }