結果
問題 | No.1382 Travel in Mitaru city |
ユーザー | tenten |
提出日時 | 2024-07-23 09:22:48 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 770 ms / 2,000 ms |
コード長 | 2,219 bytes |
コンパイル時間 | 2,656 ms |
コンパイル使用メモリ | 91,228 KB |
実行使用メモリ | 74,520 KB |
最終ジャッジ日時 | 2024-07-23 09:23:29 |
合計ジャッジ時間 | 40,418 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 63 ms
50,664 KB |
testcase_01 | AC | 61 ms
50,776 KB |
testcase_02 | AC | 59 ms
50,420 KB |
testcase_03 | AC | 59 ms
50,752 KB |
testcase_04 | AC | 60 ms
50,668 KB |
testcase_05 | AC | 61 ms
50,788 KB |
testcase_06 | AC | 549 ms
63,636 KB |
testcase_07 | AC | 467 ms
61,700 KB |
testcase_08 | AC | 360 ms
59,508 KB |
testcase_09 | AC | 581 ms
63,668 KB |
testcase_10 | AC | 550 ms
63,516 KB |
testcase_11 | AC | 623 ms
64,596 KB |
testcase_12 | AC | 616 ms
64,856 KB |
testcase_13 | AC | 682 ms
65,088 KB |
testcase_14 | AC | 620 ms
64,588 KB |
testcase_15 | AC | 581 ms
64,736 KB |
testcase_16 | AC | 741 ms
72,996 KB |
testcase_17 | AC | 724 ms
73,000 KB |
testcase_18 | AC | 770 ms
72,776 KB |
testcase_19 | AC | 731 ms
72,852 KB |
testcase_20 | AC | 768 ms
72,920 KB |
testcase_21 | AC | 737 ms
72,648 KB |
testcase_22 | AC | 720 ms
72,776 KB |
testcase_23 | AC | 758 ms
73,072 KB |
testcase_24 | AC | 721 ms
72,864 KB |
testcase_25 | AC | 744 ms
72,844 KB |
testcase_26 | AC | 648 ms
72,900 KB |
testcase_27 | AC | 703 ms
72,980 KB |
testcase_28 | AC | 631 ms
72,952 KB |
testcase_29 | AC | 707 ms
72,748 KB |
testcase_30 | AC | 656 ms
72,704 KB |
testcase_31 | AC | 553 ms
68,092 KB |
testcase_32 | AC | 633 ms
72,432 KB |
testcase_33 | AC | 628 ms
73,332 KB |
testcase_34 | AC | 484 ms
65,680 KB |
testcase_35 | AC | 403 ms
63,628 KB |
testcase_36 | AC | 496 ms
70,684 KB |
testcase_37 | AC | 221 ms
56,548 KB |
testcase_38 | AC | 523 ms
73,472 KB |
testcase_39 | AC | 278 ms
59,180 KB |
testcase_40 | AC | 467 ms
66,404 KB |
testcase_41 | AC | 465 ms
66,772 KB |
testcase_42 | AC | 510 ms
74,160 KB |
testcase_43 | AC | 482 ms
70,504 KB |
testcase_44 | AC | 310 ms
60,260 KB |
testcase_45 | AC | 474 ms
67,516 KB |
testcase_46 | AC | 379 ms
61,684 KB |
testcase_47 | AC | 725 ms
74,520 KB |
testcase_48 | AC | 567 ms
65,752 KB |
testcase_49 | AC | 757 ms
73,376 KB |
testcase_50 | AC | 486 ms
63,728 KB |
testcase_51 | AC | 545 ms
67,712 KB |
testcase_52 | AC | 633 ms
73,544 KB |
testcase_53 | AC | 296 ms
59,840 KB |
testcase_54 | AC | 409 ms
63,572 KB |
testcase_55 | AC | 613 ms
72,724 KB |
testcase_56 | AC | 350 ms
61,084 KB |
testcase_57 | AC | 483 ms
65,476 KB |
testcase_58 | AC | 206 ms
57,912 KB |
testcase_59 | AC | 346 ms
60,056 KB |
testcase_60 | AC | 614 ms
73,892 KB |
testcase_61 | AC | 161 ms
53,576 KB |
testcase_62 | AC | 62 ms
50,688 KB |
testcase_63 | AC | 317 ms
59,604 KB |
testcase_64 | AC | 190 ms
55,044 KB |
testcase_65 | AC | 94 ms
51,712 KB |
testcase_66 | AC | 156 ms
54,756 KB |
testcase_67 | AC | 172 ms
54,644 KB |
testcase_68 | AC | 203 ms
56,724 KB |
testcase_69 | AC | 159 ms
54,896 KB |
testcase_70 | AC | 225 ms
57,924 KB |
ソースコード
import java.io.*; import java.util.*; import java.util.function.*; import java.util.stream.*; public class Main { public static void main(String[] args) throws Exception { Scanner sc = new Scanner(); int n = sc.nextInt(); int m = sc.nextInt(); int start = sc.nextInt() - 1; int goal = sc.nextInt() - 1; List<List<Integer>> graph = new ArrayList<>(); int[] values = new int[n]; for (int i = 0; i < n; i++) { graph.add(new ArrayList<>()); values[i] = sc.nextInt(); } 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); } PriorityQueue<Integer> queue = new PriorityQueue<>((a, b) -> values[b] - values[a]); boolean[] visited = new boolean[n]; queue.add(start); int current = values[start]; int ans = 0; while (queue.size() > 0) { int idx = queue.poll(); if (visited[idx]) { continue; } visited[idx] = true; if (current > values[idx]) { current = values[idx]; ans++; } queue.addAll(graph.get(idx)); } System.out.println(ans); } } class Scanner { BufferedReader br; StringTokenizer st = new StringTokenizer(""); StringBuilder sb = new StringBuilder(); public Scanner() { try { br = new BufferedReader(new InputStreamReader(System.in)); } catch (Exception e) { } } public int nextInt() { return Integer.parseInt(next()); } public long nextLong() { return Long.parseLong(next()); } public double nextDouble() { return Double.parseDouble(next()); } public String next() { try { while (!st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } } catch (Exception e) { e.printStackTrace(); } finally { return st.nextToken(); } } }