結果
問題 | No.1382 Travel in Mitaru city |
ユーザー | tenten |
提出日時 | 2023-01-12 10:00:42 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 639 ms / 2,000 ms |
コード長 | 2,949 bytes |
コンパイル時間 | 2,329 ms |
コンパイル使用メモリ | 91,788 KB |
実行使用メモリ | 65,492 KB |
最終ジャッジ日時 | 2024-06-02 08:15:53 |
合計ジャッジ時間 | 33,451 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 44 ms
36,960 KB |
testcase_01 | AC | 45 ms
37,252 KB |
testcase_02 | AC | 46 ms
37,228 KB |
testcase_03 | AC | 45 ms
37,096 KB |
testcase_04 | AC | 45 ms
37,144 KB |
testcase_05 | AC | 45 ms
37,164 KB |
testcase_06 | AC | 411 ms
53,236 KB |
testcase_07 | AC | 376 ms
51,312 KB |
testcase_08 | AC | 269 ms
49,832 KB |
testcase_09 | AC | 429 ms
54,440 KB |
testcase_10 | AC | 418 ms
52,624 KB |
testcase_11 | AC | 495 ms
55,608 KB |
testcase_12 | AC | 496 ms
54,548 KB |
testcase_13 | AC | 527 ms
56,448 KB |
testcase_14 | AC | 462 ms
54,292 KB |
testcase_15 | AC | 465 ms
54,360 KB |
testcase_16 | AC | 607 ms
61,964 KB |
testcase_17 | AC | 639 ms
61,756 KB |
testcase_18 | AC | 627 ms
62,088 KB |
testcase_19 | AC | 605 ms
62,272 KB |
testcase_20 | AC | 621 ms
61,760 KB |
testcase_21 | AC | 586 ms
62,136 KB |
testcase_22 | AC | 618 ms
62,676 KB |
testcase_23 | AC | 628 ms
62,116 KB |
testcase_24 | AC | 623 ms
62,028 KB |
testcase_25 | AC | 621 ms
62,064 KB |
testcase_26 | AC | 566 ms
61,992 KB |
testcase_27 | AC | 582 ms
62,024 KB |
testcase_28 | AC | 606 ms
62,376 KB |
testcase_29 | AC | 591 ms
62,536 KB |
testcase_30 | AC | 510 ms
62,304 KB |
testcase_31 | AC | 497 ms
60,028 KB |
testcase_32 | AC | 545 ms
62,592 KB |
testcase_33 | AC | 538 ms
61,452 KB |
testcase_34 | AC | 394 ms
55,700 KB |
testcase_35 | AC | 342 ms
52,592 KB |
testcase_36 | AC | 427 ms
59,852 KB |
testcase_37 | AC | 186 ms
46,612 KB |
testcase_38 | AC | 483 ms
61,888 KB |
testcase_39 | AC | 227 ms
47,780 KB |
testcase_40 | AC | 403 ms
56,404 KB |
testcase_41 | AC | 436 ms
59,680 KB |
testcase_42 | AC | 492 ms
61,932 KB |
testcase_43 | AC | 420 ms
59,928 KB |
testcase_44 | AC | 268 ms
50,184 KB |
testcase_45 | AC | 415 ms
59,216 KB |
testcase_46 | AC | 289 ms
48,704 KB |
testcase_47 | AC | 576 ms
64,548 KB |
testcase_48 | AC | 472 ms
57,920 KB |
testcase_49 | AC | 628 ms
65,492 KB |
testcase_50 | AC | 393 ms
53,532 KB |
testcase_51 | AC | 505 ms
61,028 KB |
testcase_52 | AC | 535 ms
63,264 KB |
testcase_53 | AC | 249 ms
48,636 KB |
testcase_54 | AC | 354 ms
53,412 KB |
testcase_55 | AC | 521 ms
62,060 KB |
testcase_56 | AC | 302 ms
51,344 KB |
testcase_57 | AC | 404 ms
55,856 KB |
testcase_58 | AC | 175 ms
47,580 KB |
testcase_59 | AC | 285 ms
50,928 KB |
testcase_60 | AC | 493 ms
60,864 KB |
testcase_61 | AC | 131 ms
42,692 KB |
testcase_62 | AC | 46 ms
37,208 KB |
testcase_63 | AC | 258 ms
48,348 KB |
testcase_64 | AC | 153 ms
41,848 KB |
testcase_65 | AC | 86 ms
38,612 KB |
testcase_66 | AC | 128 ms
42,540 KB |
testcase_67 | AC | 134 ms
42,220 KB |
testcase_68 | AC | 161 ms
43,116 KB |
testcase_69 | AC | 128 ms
41,108 KB |
testcase_70 | AC | 183 ms
45,420 KB |
ソースコード
import java.io.*; import java.util.*; 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 s = sc.nextInt() - 1; int t = sc.nextInt() - 1; int[] amounts = new int[n]; ArrayList<ArrayList<Integer>> graph = new ArrayList<>(); for (int i = 0; i < n; i++) { amounts[i] = sc.nextInt(); graph.add(new ArrayList<>()); } 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<Path> queue = new PriorityQueue<>(); queue.add(new Path(s, amounts[s])); boolean[] visited = new boolean[n]; int current = Integer.MAX_VALUE; int ans = 0; while (queue.size() > 0) { Path p = queue.poll(); if (visited[p.idx]) { continue; } visited[p.idx] = true; if (p.value < current) { ans++; current = p.value; } for (int x : graph.get(p.idx)) { queue.add(new Path(x, amounts[x])); } } System.out.println(ans - 1); } static class Path implements Comparable<Path> { int idx; int value; public Path(int idx, int value) { this.idx = idx; this.value = value; } public int compareTo(Path another) { return another.value - value; } } } class Utilities { static String arrayToLineString(Object[] arr) { return Arrays.stream(arr).map(x -> x.toString()).collect(Collectors.joining("\n")); } static String arrayToLineString(int[] arr) { return String.join("\n", Arrays.stream(arr).mapToObj(String::valueOf).toArray(String[]::new)); } } class Scanner { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""); StringBuilder sb = new StringBuilder(); public Scanner() throws Exception { } public int nextInt() throws Exception { return Integer.parseInt(next()); } public long nextLong() throws Exception { return Long.parseLong(next()); } public double nextDouble() throws Exception { return Double.parseDouble(next()); } public int[] nextIntArray() throws Exception { return Stream.of(br.readLine().split(" ")).mapToInt(Integer::parseInt).toArray(); } public String next() throws Exception { while (!st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } return st.nextToken(); } }