結果

問題 No.1473 おでぶなおばけさん
ユーザー 小野寺健小野寺健
提出日時 2021-04-26 11:45:41
言語 Java21
(openjdk 21)
結果
TLE  
実行時間 -
コード長 1,747 bytes
コンパイル時間 5,571 ms
コンパイル使用メモリ 83,416 KB
実行使用メモリ 82,488 KB
最終ジャッジ日時 2023-09-18 03:44:38
合計ジャッジ時間 57,402 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 128 ms
63,412 KB
testcase_01 AC 127 ms
55,900 KB
testcase_02 AC 1,496 ms
80,904 KB
testcase_03 AC 1,292 ms
76,696 KB
testcase_04 AC 1,157 ms
71,300 KB
testcase_05 AC 739 ms
67,324 KB
testcase_06 AC 1,427 ms
79,024 KB
testcase_07 AC 1,523 ms
82,488 KB
testcase_08 AC 1,749 ms
81,056 KB
testcase_09 AC 1,515 ms
80,716 KB
testcase_10 AC 1,052 ms
71,208 KB
testcase_11 AC 1,059 ms
71,068 KB
testcase_12 AC 1,058 ms
70,860 KB
testcase_13 AC 872 ms
69,200 KB
testcase_14 AC 715 ms
66,708 KB
testcase_15 AC 1,007 ms
70,552 KB
testcase_16 AC 1,043 ms
70,848 KB
testcase_17 AC 348 ms
60,568 KB
testcase_18 AC 439 ms
60,304 KB
testcase_19 AC 1,045 ms
68,556 KB
testcase_20 AC 1,196 ms
75,988 KB
testcase_21 AC 1,186 ms
71,108 KB
testcase_22 AC 1,137 ms
78,944 KB
testcase_23 AC 1,063 ms
76,464 KB
testcase_24 AC 1,114 ms
75,648 KB
testcase_25 AC 1,181 ms
76,320 KB
testcase_26 AC 1,128 ms
76,584 KB
testcase_27 AC 708 ms
67,324 KB
testcase_28 AC 1,251 ms
81,056 KB
testcase_29 AC 1,127 ms
71,476 KB
testcase_30 AC 1,267 ms
76,296 KB
testcase_31 AC 1,289 ms
80,964 KB
testcase_32 AC 1,349 ms
78,856 KB
testcase_33 AC 1,077 ms
75,700 KB
testcase_34 AC 738 ms
69,264 KB
testcase_35 AC 870 ms
69,004 KB
testcase_36 AC 1,080 ms
71,532 KB
testcase_37 AC 1,082 ms
74,124 KB
testcase_38 AC 477 ms
60,860 KB
testcase_39 AC 1,032 ms
70,712 KB
testcase_40 AC 1,029 ms
70,940 KB
testcase_41 AC 1,067 ms
70,808 KB
testcase_42 AC 1,092 ms
70,848 KB
testcase_43 AC 983 ms
78,536 KB
testcase_44 AC 985 ms
78,860 KB
testcase_45 AC 958 ms
78,588 KB
testcase_46 TLE -
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 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 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 Q(t, d));
			V.get(t).add(new Q(s, d));
			max_d = Math.max(max_d,  d);
			min_d = Math.min(min_d,  d);
		}
		scan.close();
		for (int i=0; i < n; i++) {
			V.get(i).sort((a,b) -> b.d - a.d);
		}
		Q l = new Q(min_d - 1, 0), r = new Q(max_d + 1, 0);
		while (r.i - l.i > 1) {
			int mid = (r.i + l.i) / 2;
			int c = bfs(mid);
			if (c == 0) {
				r.i = mid;
				r.d = 0;
			} else {
				l.i = mid;
				l.d = c;
			}
		}
		System.out.println(String.format("%d %d", l.i,l.d));
	}
	
	private static int bfs(int w) {
		boolean[]B = new boolean[n];
		List<Integer> fw = new ArrayList<Integer>();
		fw.add(0);
		int depth = 1;
		while (true) {
			List<Integer> newfw = new ArrayList<Integer>();
			for (int i : fw) {
				B[i] = true;
				for (Q q : V.get(i)) {
					if (q.d >= w) {
						if (q.i == n - 1) {
							return depth;
						}
						if (!B[q.i]) {
							newfw.add(q.i);
						}
					} else {
						break;
					}
				}
			}
			if (newfw.isEmpty()) {
				depth = 0;
				break;
			}
			fw = newfw;
			depth++;
		}
		return depth;
	}
}
0