結果

問題 No.1473 おでぶなおばけさん
ユーザー 小野寺健小野寺健
提出日時 2021-04-26 08:30:41
言語 Java21
(openjdk 21)
結果
TLE  
実行時間 -
コード長 1,424 bytes
コンパイル時間 4,353 ms
コンパイル使用メモリ 77,392 KB
実行使用メモリ 96,336 KB
最終ジャッジ日時 2023-09-17 23:13:54
合計ジャッジ時間 11,451 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 131 ms
59,984 KB
testcase_01 AC 134 ms
55,644 KB
testcase_02 TLE -
testcase_03 AC 1,601 ms
90,428 KB
testcase_04 AC 1,466 ms
79,228 KB
testcase_05 AC 1,080 ms
68,728 KB
testcase_06 TLE -
testcase_07 TLE -
testcase_08 TLE -
testcase_09 AC 1,883 ms
92,448 KB
testcase_10 AC 1,147 ms
78,356 KB
testcase_11 AC 1,165 ms
79,888 KB
testcase_12 AC 1,194 ms
82,272 KB
testcase_13 AC 883 ms
70,768 KB
testcase_14 AC 757 ms
69,176 KB
testcase_15 AC 985 ms
74,372 KB
testcase_16 AC 1,153 ms
78,556 KB
testcase_17 AC 357 ms
60,584 KB
testcase_18 AC 462 ms
60,716 KB
testcase_19 AC 1,333 ms
76,632 KB
testcase_20 AC 1,306 ms
81,376 KB
testcase_21 TLE -
testcase_22 AC 1,466 ms
80,788 KB
testcase_23 AC 1,132 ms
78,940 KB
testcase_24 AC 1,384 ms
78,648 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 = new int[] {0, 0}, r = new int[] {max_d + 1, 0};
		while (r[0] - l[0] > 1) {
			int mid = (r[0] + l[0]) / 2;
			int c = bfs(mid);
			if (c == 0) {
				r[0] = mid;
				r[1] = 0;
			} else {
				l[0] = mid;
				l[1] = c;
			}
		}
		System.out.println(String.format("%d %d", l[0],l[1]));
	}
	
	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