結果

問題 No.1382 Travel in Mitaru city
ユーザー tentententen
提出日時 2023-01-12 10:00:42
言語 Java21
(openjdk 21)
結果
AC  
実行時間 739 ms / 2,000 ms
コード長 2,949 bytes
コンパイル時間 2,486 ms
コンパイル使用メモリ 85,652 KB
実行使用メモリ 62,268 KB
最終ジャッジ日時 2023-08-24 18:38:36
合計ジャッジ時間 40,564 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
33,616 KB
testcase_01 AC 43 ms
33,748 KB
testcase_02 AC 43 ms
34,056 KB
testcase_03 AC 43 ms
33,564 KB
testcase_04 AC 44 ms
33,892 KB
testcase_05 AC 43 ms
33,584 KB
testcase_06 AC 466 ms
50,068 KB
testcase_07 AC 429 ms
47,644 KB
testcase_08 AC 302 ms
45,176 KB
testcase_09 AC 500 ms
51,032 KB
testcase_10 AC 479 ms
50,956 KB
testcase_11 AC 573 ms
52,184 KB
testcase_12 AC 537 ms
51,680 KB
testcase_13 AC 550 ms
51,928 KB
testcase_14 AC 517 ms
51,680 KB
testcase_15 AC 534 ms
50,760 KB
testcase_16 AC 713 ms
60,040 KB
testcase_17 AC 667 ms
59,672 KB
testcase_18 AC 672 ms
60,172 KB
testcase_19 AC 699 ms
60,016 KB
testcase_20 AC 674 ms
59,996 KB
testcase_21 AC 669 ms
60,128 KB
testcase_22 AC 706 ms
59,804 KB
testcase_23 AC 663 ms
59,992 KB
testcase_24 AC 683 ms
59,932 KB
testcase_25 AC 678 ms
59,760 KB
testcase_26 AC 654 ms
59,820 KB
testcase_27 AC 668 ms
59,412 KB
testcase_28 AC 636 ms
60,296 KB
testcase_29 AC 640 ms
60,464 KB
testcase_30 AC 601 ms
60,796 KB
testcase_31 AC 546 ms
57,420 KB
testcase_32 AC 605 ms
60,684 KB
testcase_33 AC 580 ms
59,592 KB
testcase_34 AC 433 ms
52,472 KB
testcase_35 AC 373 ms
49,340 KB
testcase_36 AC 506 ms
57,580 KB
testcase_37 AC 218 ms
42,208 KB
testcase_38 AC 527 ms
58,840 KB
testcase_39 AC 242 ms
44,536 KB
testcase_40 AC 450 ms
53,968 KB
testcase_41 AC 478 ms
57,040 KB
testcase_42 AC 522 ms
59,088 KB
testcase_43 AC 484 ms
57,496 KB
testcase_44 AC 288 ms
46,568 KB
testcase_45 AC 458 ms
56,128 KB
testcase_46 AC 330 ms
49,124 KB
testcase_47 AC 675 ms
62,016 KB
testcase_48 AC 543 ms
54,972 KB
testcase_49 AC 739 ms
62,268 KB
testcase_50 AC 455 ms
49,048 KB
testcase_51 AC 562 ms
58,140 KB
testcase_52 AC 661 ms
60,168 KB
testcase_53 AC 267 ms
45,788 KB
testcase_54 AC 371 ms
49,604 KB
testcase_55 AC 581 ms
58,636 KB
testcase_56 AC 326 ms
47,068 KB
testcase_57 AC 445 ms
52,196 KB
testcase_58 AC 186 ms
44,704 KB
testcase_59 AC 320 ms
47,784 KB
testcase_60 AC 594 ms
57,792 KB
testcase_61 AC 138 ms
39,540 KB
testcase_62 AC 45 ms
34,084 KB
testcase_63 AC 270 ms
44,140 KB
testcase_64 AC 160 ms
40,492 KB
testcase_65 AC 74 ms
34,932 KB
testcase_66 AC 134 ms
39,472 KB
testcase_67 AC 142 ms
40,032 KB
testcase_68 AC 175 ms
41,008 KB
testcase_69 AC 135 ms
39,272 KB
testcase_70 AC 202 ms
43,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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();
    }
    
}
0