結果

問題 No.1473 おでぶなおばけさん
ユーザー 小野寺健小野寺健
提出日時 2021-04-26 14:46:51
言語 Java21
(openjdk 21)
結果
TLE  
実行時間 -
コード長 1,602 bytes
コンパイル時間 3,545 ms
コンパイル使用メモリ 84,936 KB
実行使用メモリ 83,216 KB
最終ジャッジ日時 2023-09-18 07:35:01
合計ジャッジ時間 37,645 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 123 ms
56,348 KB
testcase_01 AC 120 ms
56,388 KB
testcase_02 AC 1,770 ms
83,216 KB
testcase_03 AC 1,423 ms
80,236 KB
testcase_04 AC 1,148 ms
71,560 KB
testcase_05 AC 676 ms
67,168 KB
testcase_06 AC 1,606 ms
79,144 KB
testcase_07 AC 1,565 ms
81,324 KB
testcase_08 AC 1,606 ms
81,584 KB
testcase_09 AC 1,452 ms
79,476 KB
testcase_10 AC 1,211 ms
71,680 KB
testcase_11 AC 1,208 ms
71,480 KB
testcase_12 AC 1,151 ms
72,336 KB
testcase_13 AC 957 ms
69,724 KB
testcase_14 AC 812 ms
67,060 KB
testcase_15 AC 1,146 ms
70,984 KB
testcase_16 AC 1,239 ms
71,876 KB
testcase_17 AC 358 ms
60,688 KB
testcase_18 AC 451 ms
60,536 KB
testcase_19 AC 1,051 ms
70,800 KB
testcase_20 AC 1,321 ms
76,120 KB
testcase_21 AC 1,395 ms
71,380 KB
testcase_22 TLE -
testcase_23 AC 1,617 ms
79,040 KB
testcase_24 TLE -
testcase_25 TLE -
testcase_26 TLE -
testcase_27 AC 915 ms
68,828 KB
testcase_28 AC 1,342 ms
81,164 KB
testcase_29 AC 1,110 ms
71,708 KB
testcase_30 AC 1,293 ms
76,992 KB
testcase_31 AC 1,363 ms
80,932 KB
testcase_32 AC 1,312 ms
78,816 KB
testcase_33 AC 1,127 ms
76,212 KB
testcase_34 AC 916 ms
69,800 KB
testcase_35 AC 828 ms
68,992 KB
testcase_36 AC 1,527 ms
70,932 KB
testcase_37 AC 1,758 ms
76,828 KB
testcase_38 AC 571 ms
62,564 KB
testcase_39 AC 1,186 ms
73,784 KB
testcase_40 AC 1,136 ms
71,968 KB
testcase_41 AC 1,228 ms
70,888 KB
testcase_42 AC 1,241 ms
71,884 KB
testcase_43 TLE -
testcase_44 -- -
testcase_45 -- -
testcase_46 -- -
testcase_47 -- -
testcase_48 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

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;
						que.add(nv.i);
					}
				}
			}
		}
		return dist[n-1];
	}
}
0