結果
| 問題 | No.1473 おでぶなおばけさん |
| コンテスト | |
| ユーザー |
tenten
|
| 提出日時 | 2021-04-13 13:29:00 |
| 言語 | Java (openjdk 23) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 2,916 bytes |
| 記録 | |
| コンパイル時間 | 2,169 ms |
| コンパイル使用メモリ | 81,228 KB |
| 実行使用メモリ | 97,016 KB |
| 最終ジャッジ日時 | 2024-06-29 14:05:17 |
| 合計ジャッジ時間 | 19,020 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 45 TLE * 2 |
ソースコード
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;
} 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();
}
}
tenten