結果
問題 | No.1382 Travel in Mitaru city |
ユーザー | tenten |
提出日時 | 2023-07-12 08:48:43 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 732 ms / 2,000 ms |
コード長 | 2,900 bytes |
コンパイル時間 | 2,743 ms |
コンパイル使用メモリ | 90,224 KB |
実行使用メモリ | 73,736 KB |
最終ジャッジ日時 | 2024-09-13 22:41:46 |
合計ジャッジ時間 | 37,207 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge6 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 54 ms
50,520 KB |
testcase_01 | AC | 53 ms
50,412 KB |
testcase_02 | AC | 53 ms
50,012 KB |
testcase_03 | AC | 53 ms
50,416 KB |
testcase_04 | AC | 54 ms
50,524 KB |
testcase_05 | AC | 54 ms
50,152 KB |
testcase_06 | AC | 472 ms
63,372 KB |
testcase_07 | AC | 421 ms
51,828 KB |
testcase_08 | AC | 317 ms
49,312 KB |
testcase_09 | AC | 506 ms
54,076 KB |
testcase_10 | AC | 473 ms
54,192 KB |
testcase_11 | AC | 542 ms
54,908 KB |
testcase_12 | AC | 564 ms
56,248 KB |
testcase_13 | AC | 593 ms
55,816 KB |
testcase_14 | AC | 557 ms
54,684 KB |
testcase_15 | AC | 548 ms
54,604 KB |
testcase_16 | AC | 711 ms
62,864 KB |
testcase_17 | AC | 699 ms
63,436 KB |
testcase_18 | AC | 709 ms
62,872 KB |
testcase_19 | AC | 713 ms
73,144 KB |
testcase_20 | AC | 732 ms
72,384 KB |
testcase_21 | AC | 725 ms
72,368 KB |
testcase_22 | AC | 713 ms
72,720 KB |
testcase_23 | AC | 707 ms
72,528 KB |
testcase_24 | AC | 708 ms
72,908 KB |
testcase_25 | AC | 710 ms
72,732 KB |
testcase_26 | AC | 698 ms
72,252 KB |
testcase_27 | AC | 658 ms
72,520 KB |
testcase_28 | AC | 642 ms
72,328 KB |
testcase_29 | AC | 681 ms
72,604 KB |
testcase_30 | AC | 666 ms
72,796 KB |
testcase_31 | AC | 571 ms
71,008 KB |
testcase_32 | AC | 572 ms
71,132 KB |
testcase_33 | AC | 611 ms
73,736 KB |
testcase_34 | AC | 471 ms
65,472 KB |
testcase_35 | AC | 385 ms
64,440 KB |
testcase_36 | AC | 492 ms
70,856 KB |
testcase_37 | AC | 211 ms
56,436 KB |
testcase_38 | AC | 538 ms
72,296 KB |
testcase_39 | AC | 255 ms
58,580 KB |
testcase_40 | AC | 468 ms
67,100 KB |
testcase_41 | AC | 458 ms
68,544 KB |
testcase_42 | AC | 526 ms
72,212 KB |
testcase_43 | AC | 481 ms
71,268 KB |
testcase_44 | AC | 301 ms
60,712 KB |
testcase_45 | AC | 461 ms
67,116 KB |
testcase_46 | AC | 360 ms
61,500 KB |
testcase_47 | AC | 637 ms
72,172 KB |
testcase_48 | AC | 557 ms
67,052 KB |
testcase_49 | AC | 725 ms
72,696 KB |
testcase_50 | AC | 456 ms
65,296 KB |
testcase_51 | AC | 543 ms
70,928 KB |
testcase_52 | AC | 618 ms
72,860 KB |
testcase_53 | AC | 279 ms
60,384 KB |
testcase_54 | AC | 386 ms
65,004 KB |
testcase_55 | AC | 620 ms
71,936 KB |
testcase_56 | AC | 325 ms
60,096 KB |
testcase_57 | AC | 466 ms
65,740 KB |
testcase_58 | AC | 184 ms
57,620 KB |
testcase_59 | AC | 326 ms
60,036 KB |
testcase_60 | AC | 608 ms
71,956 KB |
testcase_61 | AC | 149 ms
53,840 KB |
testcase_62 | AC | 55 ms
50,284 KB |
testcase_63 | AC | 289 ms
59,128 KB |
testcase_64 | AC | 165 ms
55,000 KB |
testcase_65 | AC | 87 ms
51,484 KB |
testcase_66 | AC | 147 ms
52,340 KB |
testcase_67 | AC | 155 ms
54,088 KB |
testcase_68 | AC | 187 ms
55,012 KB |
testcase_69 | AC | 147 ms
54,148 KB |
testcase_70 | AC | 211 ms
57,364 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[] values = new int[n]; ArrayList<ArrayList<City>> graph = new ArrayList<>(); for (int i = 0; i < n; i++) { values[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(new City(b, values[b])); graph.get(b).add(new City(a, values[a])); } int current = values[s]; int ans = 0; PriorityQueue<City> queue = new PriorityQueue<>(); queue.add(new City(s, values[s])); boolean[] visited = new boolean[n]; while (queue.size() > 0) { City x = queue.poll(); if (visited[x.idx]) { continue; } visited[x.idx] = true; if (x.value < current) { current = x.value; ans++; } queue.addAll(graph.get(x.idx)); } System.out.println(ans); } static class City implements Comparable<City> { int idx; int value; public City(int idx, int value) { this.idx = idx; this.value = value; } public int compareTo(City 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(); } }