結果

問題 No.1607 Kth Maximum Card
ユーザー tentententen
提出日時 2021-10-21 18:13:22
言語 Java21
(openjdk 21)
結果
TLE  
実行時間 -
コード長 2,651 bytes
コンパイル時間 4,220 ms
コンパイル使用メモリ 79,784 KB
実行使用メモリ 148,416 KB
最終ジャッジ日時 2023-10-21 13:01:08
合計ジャッジ時間 13,534 ms
ジャッジサーバーID
(参考情報)
judge9 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 56 ms
36,880 KB
testcase_01 AC 53 ms
36,928 KB
testcase_02 AC 55 ms
36,864 KB
testcase_03 AC 57 ms
53,648 KB
testcase_04 AC 52 ms
36,872 KB
testcase_05 AC 52 ms
36,856 KB
testcase_06 AC 57 ms
36,936 KB
testcase_07 AC 52 ms
36,880 KB
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 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

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

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        int n = sc.nextInt();
        int m = sc.nextInt();
        int k = sc.nextInt();
        ArrayList<HashMap<Integer, Integer>> graph = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            graph.add(new HashMap<>());
        }
        for (int i = 0; i < m; i++) {
            int a = sc.nextInt() - 1;
            int b = sc.nextInt() - 1;
            int c = sc.nextInt();
            graph.get(a).put(b, c);
            graph.get(b).put(a, c);
        }
        PriorityQueue<Path> queue = new PriorityQueue<>();
        int[] costs = new int[n];
        int left = -1;
        int right = 200000;
        while (right - left > 1) {
            int mm = (left + right) / 2;
            queue.add(new Path(0, 0));
            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) > mm) {
                        queue.add(new Path(x, p.value + 1));
                    } else {
                        queue.add(new Path(x, p.value));
                    }
                }
            }
            if (costs[n - 1] >= k) {
                left = mm;
            } else {
                right = mm;
            }
        }
        System.out.println(right);
    }
    
    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 nextLine() throws Exception {
        return br.readLine();
    }
    
    public String next() throws Exception {
        if (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
}
0