結果
問題 |
No.1473 おでぶなおばけさん
|
ユーザー |
|
提出日時 | 2021-04-26 08:53:50 |
言語 | Java (openjdk 23) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,552 bytes |
コンパイル時間 | 4,324 ms |
コンパイル使用メモリ | 78,724 KB |
実行使用メモリ | 85,816 KB |
最終ジャッジ日時 | 2024-07-04 17:32:24 |
合計ジャッジ時間 | 62,796 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 41 TLE * 1 -- * 5 |
ソースコード
package yukicoder; import java.util.Scanner; import java.util.List; import java.util.ArrayList; public class No1473_2 { private static class Q { public int i; public long d; public Q(int i, long 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>()); } long max_d = 0; long min_d = Long.MAX_VALUE; for (int i=0; i < m; i++) { int s = scan.nextInt() - 1; int t = scan.nextInt() - 1; long d = scan.nextLong(); V.get(s).add(new Q(t, d)); V.get(t).add(new Q(s, d)); max_d = Math.max(max_d, d); min_d = Math.min(min_d, d); } scan.close(); Q l = new Q(0, min_d - 1), r = new Q(0, max_d + 1); while (r.d - l.d > 1) { long mid = (r.d + l.d) / 2; int c = bfs(mid); if (c == 0) { r.d = mid; r.i = 0; } else { l.d = mid; l.i = c; } } System.out.println(String.format("%d %d", l.d,l.i)); } private static int bfs(long w) { boolean[] B = new boolean[n]; List<Integer[]> q = new ArrayList<Integer[]>(); q.add(new Integer[] {0, 0}); B[0] = true; while (q.size() > 0) { Integer[] v = q.remove(0); if (v[0] == n-1) { return v[1]; } B[v[0]] = true; for (Q i : V.get(v[0])) { if (i.d >= w && !B[i.i]) { q.add(new Integer[] {i.i, v[1] + 1}); } } } return 0; } }