結果

問題 No.1382 Travel in Mitaru city
ユーザー tentententen
提出日時 2023-07-12 08:48:43
言語 Java21
(openjdk 21)
結果
AC  
実行時間 778 ms / 2,000 ms
コード長 2,900 bytes
コンパイル時間 3,290 ms
コンパイル使用メモリ 85,212 KB
実行使用メモリ 75,460 KB
最終ジャッジ日時 2023-10-11 22:53:44
合計ジャッジ時間 39,372 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 45 ms
49,528 KB
testcase_01 AC 44 ms
49,612 KB
testcase_02 AC 45 ms
49,688 KB
testcase_03 AC 44 ms
49,580 KB
testcase_04 AC 45 ms
49,948 KB
testcase_05 AC 44 ms
49,616 KB
testcase_06 AC 486 ms
63,020 KB
testcase_07 AC 408 ms
63,160 KB
testcase_08 AC 311 ms
59,568 KB
testcase_09 AC 516 ms
65,316 KB
testcase_10 AC 506 ms
65,304 KB
testcase_11 AC 542 ms
64,244 KB
testcase_12 AC 591 ms
66,264 KB
testcase_13 AC 612 ms
66,156 KB
testcase_14 AC 533 ms
63,976 KB
testcase_15 AC 536 ms
64,492 KB
testcase_16 AC 754 ms
74,016 KB
testcase_17 AC 748 ms
73,852 KB
testcase_18 AC 743 ms
74,820 KB
testcase_19 AC 771 ms
72,612 KB
testcase_20 AC 752 ms
73,884 KB
testcase_21 AC 766 ms
74,608 KB
testcase_22 AC 763 ms
74,096 KB
testcase_23 AC 752 ms
74,224 KB
testcase_24 AC 772 ms
74,480 KB
testcase_25 AC 748 ms
74,376 KB
testcase_26 AC 738 ms
74,128 KB
testcase_27 AC 693 ms
74,120 KB
testcase_28 AC 735 ms
74,704 KB
testcase_29 AC 719 ms
74,160 KB
testcase_30 AC 683 ms
74,136 KB
testcase_31 AC 549 ms
72,376 KB
testcase_32 AC 621 ms
74,632 KB
testcase_33 AC 619 ms
74,648 KB
testcase_34 AC 452 ms
64,840 KB
testcase_35 AC 387 ms
65,452 KB
testcase_36 AC 525 ms
74,352 KB
testcase_37 AC 210 ms
56,288 KB
testcase_38 AC 534 ms
74,592 KB
testcase_39 AC 259 ms
59,224 KB
testcase_40 AC 461 ms
67,804 KB
testcase_41 AC 477 ms
69,312 KB
testcase_42 AC 514 ms
74,572 KB
testcase_43 AC 502 ms
74,424 KB
testcase_44 AC 289 ms
61,456 KB
testcase_45 AC 487 ms
68,456 KB
testcase_46 AC 359 ms
61,168 KB
testcase_47 AC 727 ms
73,624 KB
testcase_48 AC 575 ms
66,640 KB
testcase_49 AC 778 ms
75,460 KB
testcase_50 AC 469 ms
63,752 KB
testcase_51 AC 555 ms
72,832 KB
testcase_52 AC 623 ms
73,944 KB
testcase_53 AC 276 ms
59,492 KB
testcase_54 AC 385 ms
64,996 KB
testcase_55 AC 626 ms
75,376 KB
testcase_56 AC 328 ms
61,984 KB
testcase_57 AC 470 ms
67,048 KB
testcase_58 AC 178 ms
56,028 KB
testcase_59 AC 315 ms
59,860 KB
testcase_60 AC 614 ms
74,808 KB
testcase_61 AC 145 ms
54,812 KB
testcase_62 AC 47 ms
49,908 KB
testcase_63 AC 292 ms
59,068 KB
testcase_64 AC 168 ms
55,308 KB
testcase_65 AC 76 ms
52,668 KB
testcase_66 AC 137 ms
54,652 KB
testcase_67 AC 149 ms
56,300 KB
testcase_68 AC 180 ms
55,328 KB
testcase_69 AC 138 ms
54,624 KB
testcase_70 AC 201 ms
57,812 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[] 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();
    }
    
}
0