結果

問題 No.1473 おでぶなおばけさん
ユーザー 小野寺健小野寺健
提出日時 2021-04-26 14:57:16
言語 Java21
(openjdk 21)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,739 bytes
コンパイル時間 4,304 ms
コンパイル使用メモリ 82,676 KB
実行使用メモリ 82,060 KB
最終ジャッジ日時 2023-09-18 07:51:01
合計ジャッジ時間 49,143 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 132 ms
56,072 KB
testcase_01 AC 132 ms
56,072 KB
testcase_02 AC 1,887 ms
82,036 KB
testcase_03 AC 1,538 ms
79,712 KB
testcase_04 AC 1,149 ms
71,500 KB
testcase_05 AC 720 ms
65,024 KB
testcase_06 AC 1,787 ms
80,032 KB
testcase_07 AC 1,735 ms
82,060 KB
testcase_08 AC 1,981 ms
81,880 KB
testcase_09 AC 1,710 ms
81,740 KB
testcase_10 AC 1,242 ms
71,968 KB
testcase_11 AC 1,325 ms
71,568 KB
testcase_12 AC 1,233 ms
72,208 KB
testcase_13 AC 962 ms
69,248 KB
testcase_14 AC 799 ms
67,408 KB
testcase_15 AC 1,203 ms
71,232 KB
testcase_16 AC 1,201 ms
71,120 KB
testcase_17 AC 363 ms
60,632 KB
testcase_18 AC 475 ms
60,980 KB
testcase_19 AC 1,144 ms
69,248 KB
testcase_20 AC 1,426 ms
76,712 KB
testcase_21 AC 1,591 ms
71,196 KB
testcase_22 TLE -
testcase_23 AC 1,714 ms
79,056 KB
testcase_24 TLE -
testcase_25 AC 1,748 ms
78,508 KB
testcase_26 AC 1,245 ms
79,180 KB
testcase_27 AC 792 ms
67,548 KB
testcase_28 AC 1,396 ms
81,276 KB
testcase_29 AC 1,216 ms
72,036 KB
testcase_30 AC 1,465 ms
76,072 KB
testcase_31 AC 1,456 ms
80,952 KB
testcase_32 AC 1,516 ms
79,076 KB
testcase_33 AC 1,176 ms
76,540 KB
testcase_34 AC 788 ms
69,484 KB
testcase_35 AC 939 ms
70,748 KB
testcase_36 AC 1,711 ms
70,872 KB
testcase_37 AC 1,252 ms
76,524 KB
testcase_38 AC 481 ms
61,284 KB
testcase_39 AC 1,224 ms
71,680 KB
testcase_40 AC 1,233 ms
71,444 KB
testcase_41 AC 1,247 ms
72,000 KB
testcase_42 AC 1,224 ms
71,012 KB
testcase_43 AC 1,224 ms
81,432 KB
testcase_44 AC 1,208 ms
79,524 KB
testcase_45 AC 1,206 ms
78,740 KB
testcase_46 AC 1,216 ms
78,052 KB
testcase_47 AC 1,397 ms
78,824 KB
testcase_48 AC 1,301 ms
79,280 KB
権限があれば一括ダウンロードができます

ソースコード

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;
		int min = Integer.MAX_VALUE;
		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);
			min = Math.min(min, d);
		}
		w[0] = min-1;
		w[m+1] = max+1;
		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];
	}
}
0