結果
| 問題 |
No.1607 Kth Maximum Card
|
| コンテスト | |
| ユーザー |
tenten
|
| 提出日時 | 2021-10-21 18:13:22 |
| 言語 | Java (openjdk 23) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 2,651 bytes |
| コンパイル時間 | 2,595 ms |
| コンパイル使用メモリ | 80,356 KB |
| 実行使用メモリ | 159,536 KB |
| 最終ジャッジ日時 | 2024-09-21 14:16:44 |
| 合計ジャッジ時間 | 10,380 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| 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 = -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();
}
}
tenten