結果

問題 No.1382 Travel in Mitaru city
ユーザー tentententen
提出日時 2023-03-23 10:02:50
言語 Java21
(openjdk 21)
結果
AC  
実行時間 910 ms / 2,000 ms
コード長 3,245 bytes
コンパイル時間 2,750 ms
コンパイル使用メモリ 93,768 KB
実行使用メモリ 83,668 KB
最終ジャッジ日時 2023-10-18 19:25:03
合計ジャッジ時間 47,888 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 55 ms
53,440 KB
testcase_01 AC 54 ms
53,440 KB
testcase_02 AC 54 ms
53,440 KB
testcase_03 AC 55 ms
53,440 KB
testcase_04 AC 55 ms
53,436 KB
testcase_05 AC 56 ms
52,456 KB
testcase_06 AC 532 ms
64,496 KB
testcase_07 AC 454 ms
64,360 KB
testcase_08 AC 348 ms
62,772 KB
testcase_09 AC 533 ms
64,528 KB
testcase_10 AC 512 ms
64,344 KB
testcase_11 AC 688 ms
69,692 KB
testcase_12 AC 708 ms
70,212 KB
testcase_13 AC 742 ms
69,936 KB
testcase_14 AC 657 ms
68,948 KB
testcase_15 AC 696 ms
69,368 KB
testcase_16 AC 858 ms
77,520 KB
testcase_17 AC 848 ms
77,164 KB
testcase_18 AC 856 ms
77,340 KB
testcase_19 AC 839 ms
75,480 KB
testcase_20 AC 858 ms
77,384 KB
testcase_21 AC 881 ms
77,728 KB
testcase_22 AC 867 ms
77,504 KB
testcase_23 AC 847 ms
77,088 KB
testcase_24 AC 844 ms
77,180 KB
testcase_25 AC 839 ms
77,456 KB
testcase_26 AC 848 ms
77,200 KB
testcase_27 AC 841 ms
77,736 KB
testcase_28 AC 838 ms
77,468 KB
testcase_29 AC 843 ms
76,996 KB
testcase_30 AC 835 ms
77,224 KB
testcase_31 AC 712 ms
78,372 KB
testcase_32 AC 776 ms
78,112 KB
testcase_33 AC 779 ms
78,444 KB
testcase_34 AC 582 ms
73,076 KB
testcase_35 AC 476 ms
68,332 KB
testcase_36 AC 630 ms
78,116 KB
testcase_37 AC 274 ms
64,500 KB
testcase_38 AC 680 ms
80,904 KB
testcase_39 AC 317 ms
62,880 KB
testcase_40 AC 592 ms
77,588 KB
testcase_41 AC 598 ms
75,772 KB
testcase_42 AC 684 ms
77,368 KB
testcase_43 AC 600 ms
78,216 KB
testcase_44 AC 399 ms
66,392 KB
testcase_45 AC 570 ms
76,140 KB
testcase_46 AC 417 ms
66,796 KB
testcase_47 AC 873 ms
78,564 KB
testcase_48 AC 677 ms
75,500 KB
testcase_49 AC 910 ms
83,668 KB
testcase_50 AC 528 ms
68,044 KB
testcase_51 AC 706 ms
77,396 KB
testcase_52 AC 806 ms
78,400 KB
testcase_53 AC 355 ms
64,584 KB
testcase_54 AC 476 ms
69,216 KB
testcase_55 AC 793 ms
79,136 KB
testcase_56 AC 413 ms
66,216 KB
testcase_57 AC 595 ms
72,936 KB
testcase_58 AC 231 ms
62,908 KB
testcase_59 AC 403 ms
66,340 KB
testcase_60 AC 712 ms
77,996 KB
testcase_61 AC 164 ms
57,476 KB
testcase_62 AC 56 ms
52,432 KB
testcase_63 AC 282 ms
62,296 KB
testcase_64 AC 179 ms
59,036 KB
testcase_65 AC 99 ms
54,340 KB
testcase_66 AC 161 ms
56,428 KB
testcase_67 AC 172 ms
60,856 KB
testcase_68 AC 191 ms
58,936 KB
testcase_69 AC 161 ms
57,396 KB
testcase_70 AC 209 ms
59,336 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;
        City[] cities = new City[n];
        ArrayList<ArrayList<City>> graph = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            cities[i] = new City(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(cities[b]);
            graph.get(b).add(cities[a]);
        }
        TreeSet<City> nextTo = new TreeSet<>();
        int current = cities[s].value;
        nextTo.addAll(graph.get(s));
        HashSet<Integer> visited = new HashSet<>();
        visited.add(s);
        int ans = 0;
        while (nextTo.size() > 0) {
            City y = nextTo.pollLast();
            if (visited.contains(y.idx)) {
                continue;
            }
            visited.add(y.idx);
            if (y.value < current) {
                ans++;
                current = y.value;
            }
            nextTo.addAll(graph.get(y.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) {
            if (value == another.value) {
                return idx - another.idx;
            } else {
                return value - another.value;
            }
        }
        
        public int hashCode() {
            return idx;
        }
        
        public boolean equals(Object o) {
            City x = (City)o;
            return x.idx == idx;
        }
    }
}
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