結果

問題 No.1473 おでぶなおばけさん
ユーザー tentententen
提出日時 2021-04-13 13:38:03
言語 Java21
(openjdk 21)
結果
TLE  
実行時間 -
コード長 3,110 bytes
コンパイル時間 2,361 ms
コンパイル使用メモリ 81,108 KB
実行使用メモリ 129,396 KB
最終ジャッジ日時 2023-09-12 01:03:09
合計ジャッジ時間 18,126 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 72 ms
50,840 KB
testcase_01 AC 72 ms
51,428 KB
testcase_02 TLE -
testcase_03 AC 1,448 ms
99,300 KB
testcase_04 AC 1,705 ms
87,352 KB
testcase_05 AC 860 ms
64,768 KB
testcase_06 TLE -
testcase_07 TLE -
testcase_08 TLE -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
testcase_45 -- -
testcase_46 -- -
testcase_47 -- -
testcase_48 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.*;

public class Main {
    static ArrayList<HashMap<Integer, Integer>> graph = new ArrayList<>();
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        int n = sc.nextInt();
        int mm = sc.nextInt();
        
        for (int i = 0; i < n; i++) {
            graph.add(new HashMap<>());
        }
        for (int i = 0; i < mm; i++) {
            int a = sc.nextInt() - 1;
            int b = sc.nextInt() - 1;
            int d = sc.nextInt();
            if (!graph.get(a).containsKey(b) || graph.get(a).get(b) < d) {
                graph.get(a).put(b, d);
            }
            if (!graph.get(b).containsKey(a) || graph.get(b).get(a) < d) {
                graph.get(b).put(a, d);
            }
        }
        int left = 0;
        int right = Integer.MAX_VALUE / 2;
        PriorityQueue<Path> queue = new PriorityQueue<>();
        int[] costs = new int[n];
        while (right - left > 1) {
            int m = (left + right) / 2;
            queue.add(new Path(0, 0));
            check(m, costs, queue);
            if (costs[n - 1] == Integer.MAX_VALUE) {
                right = m;
                for (int i = 1; i < n; i++) {
                    if (costs[i] != Integer.MAX_VALUE) {
                        queue.add(new Path(i, 0));
                    }
                }
            } else {
                left = m;
            }
        }
        queue.add(new Path(0, 0));
        check(left, costs, queue);
        System.out.println(left + " " + costs[n - 1]);
    }
    
    static void check(int size, int[] costs, PriorityQueue<Path> queue) {
             Arrays.fill(costs, Integer.MAX_VALUE);
           while (queue.size() > 0) {
                Path p = queue.poll();
                if (costs[p.idx] <= p.value) {
                    continue;
                }
                costs[p.idx] = p.value;
                for (int x : graph.get(p.idx).keySet()) {
                    if (graph.get(p.idx).get(x) < size) {
                        continue;
                    }
                    queue.add(new Path(x, p.value + 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 value - another.value;
        }
    }
}
class Scanner {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st = new StringTokenizer("");
    
    public Scanner() throws Exception {
        
    }
    
    public int nextInt() throws Exception {
        return Integer.parseInt(next());
    }
    
    public long nextLong() throws Exception {
        return Long.parseLong(next());
    }
    
    public String next() throws Exception {
        if (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
}
0