結果
問題 |
No.1607 Kth Maximum Card
|
ユーザー |
![]() |
提出日時 | 2021-07-20 15:42:29 |
言語 | Java (openjdk 23) |
結果 |
TLE
|
実行時間 | - |
コード長 | 2,557 bytes |
コンパイル時間 | 2,570 ms |
コンパイル使用メモリ | 80,064 KB |
実行使用メモリ | 57,504 KB |
最終ジャッジ日時 | 2024-07-17 13:42:30 |
合計ジャッジ時間 | 9,980 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 5 TLE * 1 -- * 27 |
ソースコード
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 = 0; int right = 200001; while (right - left > 1) { int x = (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 y : graph.get(p.idx).keySet()) { if (graph.get(p.idx).get(y) >= x) { queue.add(new Path(y, p.value + 1)); } else { queue.add(new Path(y, p.value)); } } } if (costs[n - 1] >= k) { left = x; } else { right = x; } } System.out.println(left); } 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(); } }