結果

問題 No.1473 おでぶなおばけさん
ユーザー 小野寺健小野寺健
提出日時 2021-04-26 09:05:28
言語 Java21
(openjdk 21)
結果
TLE  
実行時間 -
コード長 1,500 bytes
コンパイル時間 5,532 ms
コンパイル使用メモリ 81,708 KB
実行使用メモリ 441,512 KB
最終ジャッジ日時 2023-09-18 00:37:35
合計ジャッジ時間 61,069 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 126 ms
59,824 KB
testcase_01 AC 127 ms
55,712 KB
testcase_02 TLE -
testcase_03 AC 1,378 ms
87,512 KB
testcase_04 AC 1,243 ms
78,968 KB
testcase_05 AC 912 ms
70,816 KB
testcase_06 AC 1,857 ms
89,860 KB
testcase_07 AC 1,773 ms
91,956 KB
testcase_08 TLE -
testcase_09 AC 1,657 ms
92,116 KB
testcase_10 AC 1,123 ms
78,804 KB
testcase_11 AC 1,197 ms
80,228 KB
testcase_12 AC 1,124 ms
80,532 KB
testcase_13 AC 872 ms
70,804 KB
testcase_14 AC 712 ms
68,980 KB
testcase_15 AC 987 ms
74,804 KB
testcase_16 AC 1,100 ms
78,452 KB
testcase_17 AC 343 ms
60,420 KB
testcase_18 AC 446 ms
60,376 KB
testcase_19 AC 1,186 ms
76,416 KB
testcase_20 AC 1,181 ms
81,236 KB
testcase_21 TLE -
testcase_22 AC 1,258 ms
80,840 KB
testcase_23 AC 1,084 ms
78,940 KB
testcase_24 AC 1,230 ms
78,656 KB
testcase_25 AC 1,293 ms
83,280 KB
testcase_26 AC 1,154 ms
82,472 KB
testcase_27 AC 865 ms
69,144 KB
testcase_28 AC 1,220 ms
90,264 KB
testcase_29 AC 1,196 ms
81,020 KB
testcase_30 AC 1,373 ms
83,792 KB
testcase_31 AC 1,677 ms
89,948 KB
testcase_32 AC 1,569 ms
90,432 KB
testcase_33 AC 1,106 ms
81,100 KB
testcase_34 AC 776 ms
71,100 KB
testcase_35 AC 1,045 ms
71,236 KB
testcase_36 AC 1,952 ms
81,328 KB
testcase_37 AC 991 ms
80,532 KB
testcase_38 AC 451 ms
62,456 KB
testcase_39 AC 1,090 ms
80,560 KB
testcase_40 AC 1,095 ms
78,744 KB
testcase_41 AC 961 ms
74,088 KB
testcase_42 AC 959 ms
73,856 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;

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;
		int min_d = 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 Integer[] {t, d});
			V.get(t).add(new Integer[] {s, d});
			max_d = Math.max(max_d,  d);
			min_d = Math.min(min_d,  d);
		}
		scan.close();
		int[] l = new int[] {min_d - 1, 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});
		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 (Integer[] i : V.get(v[0])) {
				if (i[1] >= w && !B[i[0]]) {
					q.add(new Integer[] {i[0], v[1] + 1});
				}
			}
		}
		return 0;
	}

}
0