結果

問題 No.1473 おでぶなおばけさん
ユーザー 小野寺健小野寺健
提出日時 2021-04-26 08:18:55
言語 Java21
(openjdk 21)
結果
TLE  
実行時間 -
コード長 1,346 bytes
コンパイル時間 3,986 ms
コンパイル使用メモリ 74,556 KB
実行使用メモリ 81,900 KB
最終ジャッジ日時 2023-09-17 22:54:17
合計ジャッジ時間 10,742 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 123 ms
44,436 KB
testcase_01 AC 124 ms
39,320 KB
testcase_02 TLE -
testcase_03 AC 1,518 ms
74,064 KB
testcase_04 AC 1,457 ms
67,016 KB
testcase_05 AC 1,015 ms
53,236 KB
testcase_06 TLE -
testcase_07 TLE -
testcase_08 TLE -
testcase_09 AC 1,827 ms
81,900 KB
testcase_10 AC 1,156 ms
64,984 KB
testcase_11 AC 1,155 ms
65,236 KB
testcase_12 AC 1,143 ms
64,940 KB
testcase_13 AC 892 ms
56,300 KB
testcase_14 AC 724 ms
54,232 KB
testcase_15 AC 995 ms
60,780 KB
testcase_16 AC 1,217 ms
65,404 KB
testcase_17 AC 346 ms
46,468 KB
testcase_18 AC 430 ms
46,932 KB
testcase_19 AC 1,228 ms
62,784 KB
testcase_20 AC 1,308 ms
67,800 KB
testcase_21 TLE -
testcase_22 AC 1,890 ms
66,932 KB
testcase_23 AC 1,231 ms
65,216 KB
testcase_24 AC 1,750 ms
65,392 KB
testcase_25 TLE -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
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;

public class No1473_2 {
	
	private static int n;
	private static List<List<Integer[]>> V;

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		n = scan.nextInt();
		int m = scan.nextInt();
		V = new ArrayList<List<Integer[]>>();
		for (int i = 0; i < n; i++) {
			V.add(new ArrayList<Integer[]>());
		}
		int max_d = 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 Integer[] {t, d});
			V.get(t).add(new Integer[] {s, d});
			max_d = Math.max(max_d,  d);
		}
		
		int l = 0, r = max_d + 1;
		while (r - l > 1) {
			int mid = (r + l) / 2;
			int c = bfs(mid);
			if (c == 0) {
				r = mid;
			} else {
				l = mid;
			}
		}
		System.out.println(String.format("%d %d", l, bfs(l)));
	}
	
	private static int bfs(int w) {
		boolean[] B = new boolean[n];
		List<Integer[]> q = new ArrayList<Integer[]>();
		q.add(new Integer[] {0, 0});
		while (q.size() > 0) {
			Integer[] v = q.remove(0);
			if (v[0] == n-1) {
				return v[1];
			}
			if (B[v[0]]) {
				continue;
			}
			B[v[0]] = true;
			for (Integer[] i : V.get(v[0])) {
				if (i[1] >= w) {
					q.add(new Integer[] {i[0], v[1] + 1});
				}
			}
		}
		return 0;
	}

}
0