結果
| 問題 |
No.1473 おでぶなおばけさん
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-04-26 14:49:44 |
| 言語 | Java (openjdk 23) |
| 結果 |
TLE
(最新)
AC
(最初)
|
| 実行時間 | - |
| コード長 | 1,663 bytes |
| コンパイル時間 | 3,774 ms |
| コンパイル使用メモリ | 90,080 KB |
| 実行使用メモリ | 76,060 KB |
| 最終ジャッジ日時 | 2024-07-04 23:45:43 |
| 合計ジャッジ時間 | 69,739 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 45 TLE * 2 |
ソースコード
package yukicoder;
import java.util.Scanner;
import java.util.List;
import java.util.ArrayList;
import java.util.Arrays;
public class No1473_3 {
private static class Q {
int i;
int d;
public Q(int i, int d) {
this.i = i;
this.d = d;
}
}
private static int n;
private static List<List<Q>> V;
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
n = scan.nextInt();
int m = scan.nextInt();
V = new ArrayList<List<Q>>();
for (int i = 0; i < n; i++) {
V.add(new ArrayList<Q>());
}
int[] w = new int[m+2];
int max = 0;
for (int i=0; i < m; i++) {
int s = scan.nextInt() - 1;
int t = scan.nextInt() - 1;
int d = scan.nextInt();
V.get(s).add(new Q(t, d));
V.get(t).add(new Q(s, d));
w[i+1] = d;
max = Math.max(max, d);
}
w[m+1] = max;
Arrays.sort(w);
scan.close();
for (int i=0; i < n; i++) {
V.get(i).sort((a,b) -> b.d - a.d);
}
Q l = new Q(0, 0), r = new Q(m+1, 0);
while (r.i - l.i > 1) {
int mid = (r.i + l.i) / 2;
int c = bfs(w[mid]);
if (c < 0) {
r.i = mid;
r.d = 0;
} else {
l.i = mid;
l.d = c;
}
}
System.out.println(String.format("%d %d", w[l.i],l.d));
}
private static int bfs(int w) {
int[] dist = new int[n];
Arrays.fill(dist, -1);
List<Integer> que = new ArrayList<Integer>();
dist[0] = 0;
que.add(0);
while (!que.isEmpty()) {
int v = que.remove(0);
for (Q nv : V.get(v)) {
if (nv.d >= w) {
if (dist[nv.i] < 0) {
dist[nv.i] = dist[v] + 1;
if (nv.i == n - 1) {
return dist[nv.i];
}
que.add(nv.i);
}
}
}
}
return dist[n-1];
}
}