結果
問題 | No.1382 Travel in Mitaru city |
ユーザー | tenten |
提出日時 | 2023-01-12 10:00:42 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 856 ms / 2,000 ms |
コード長 | 2,949 bytes |
コンパイル時間 | 2,958 ms |
コンパイル使用メモリ | 85,316 KB |
実行使用メモリ | 65,028 KB |
最終ジャッジ日時 | 2024-12-23 03:17:39 |
合計ジャッジ時間 | 42,762 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 53 ms
37,116 KB |
testcase_01 | AC | 55 ms
37,192 KB |
testcase_02 | AC | 55 ms
37,312 KB |
testcase_03 | AC | 56 ms
37,064 KB |
testcase_04 | AC | 54 ms
37,388 KB |
testcase_05 | AC | 56 ms
37,388 KB |
testcase_06 | AC | 531 ms
53,296 KB |
testcase_07 | AC | 462 ms
51,344 KB |
testcase_08 | AC | 351 ms
48,868 KB |
testcase_09 | AC | 572 ms
54,188 KB |
testcase_10 | AC | 542 ms
53,360 KB |
testcase_11 | AC | 619 ms
54,672 KB |
testcase_12 | AC | 640 ms
55,568 KB |
testcase_13 | AC | 661 ms
55,468 KB |
testcase_14 | AC | 590 ms
55,336 KB |
testcase_15 | AC | 605 ms
55,384 KB |
testcase_16 | AC | 773 ms
61,956 KB |
testcase_17 | AC | 736 ms
62,016 KB |
testcase_18 | AC | 800 ms
62,316 KB |
testcase_19 | AC | 767 ms
61,808 KB |
testcase_20 | AC | 785 ms
62,364 KB |
testcase_21 | AC | 808 ms
62,080 KB |
testcase_22 | AC | 799 ms
61,932 KB |
testcase_23 | AC | 801 ms
62,008 KB |
testcase_24 | AC | 721 ms
61,816 KB |
testcase_25 | AC | 755 ms
61,852 KB |
testcase_26 | AC | 699 ms
62,024 KB |
testcase_27 | AC | 776 ms
62,336 KB |
testcase_28 | AC | 726 ms
62,380 KB |
testcase_29 | AC | 755 ms
62,396 KB |
testcase_30 | AC | 704 ms
62,656 KB |
testcase_31 | AC | 583 ms
59,668 KB |
testcase_32 | AC | 644 ms
62,300 KB |
testcase_33 | AC | 652 ms
61,576 KB |
testcase_34 | AC | 490 ms
55,568 KB |
testcase_35 | AC | 423 ms
52,604 KB |
testcase_36 | AC | 571 ms
59,868 KB |
testcase_37 | AC | 224 ms
46,736 KB |
testcase_38 | AC | 573 ms
61,536 KB |
testcase_39 | AC | 278 ms
47,672 KB |
testcase_40 | AC | 502 ms
56,236 KB |
testcase_41 | AC | 514 ms
59,348 KB |
testcase_42 | AC | 609 ms
61,848 KB |
testcase_43 | AC | 537 ms
59,444 KB |
testcase_44 | AC | 328 ms
49,652 KB |
testcase_45 | AC | 517 ms
58,920 KB |
testcase_46 | AC | 367 ms
49,708 KB |
testcase_47 | AC | 763 ms
64,524 KB |
testcase_48 | AC | 620 ms
57,620 KB |
testcase_49 | AC | 856 ms
65,028 KB |
testcase_50 | AC | 512 ms
53,512 KB |
testcase_51 | AC | 652 ms
59,828 KB |
testcase_52 | AC | 706 ms
62,652 KB |
testcase_53 | AC | 290 ms
48,568 KB |
testcase_54 | AC | 456 ms
51,572 KB |
testcase_55 | AC | 681 ms
62,400 KB |
testcase_56 | AC | 381 ms
50,596 KB |
testcase_57 | AC | 509 ms
55,352 KB |
testcase_58 | AC | 216 ms
47,552 KB |
testcase_59 | AC | 380 ms
50,708 KB |
testcase_60 | AC | 679 ms
61,912 KB |
testcase_61 | AC | 161 ms
42,568 KB |
testcase_62 | AC | 57 ms
37,428 KB |
testcase_63 | AC | 317 ms
48,272 KB |
testcase_64 | AC | 184 ms
43,940 KB |
testcase_65 | AC | 90 ms
38,592 KB |
testcase_66 | AC | 155 ms
42,756 KB |
testcase_67 | AC | 167 ms
43,208 KB |
testcase_68 | AC | 191 ms
43,200 KB |
testcase_69 | AC | 154 ms
40,568 KB |
testcase_70 | AC | 227 ms
47,164 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(); } }