結果

問題 No.1473 おでぶなおばけさん
ユーザー 小野寺健小野寺健
提出日時 2021-04-26 11:41:38
言語 Java21
(openjdk 21)
結果
TLE  
実行時間 -
コード長 1,683 bytes
コンパイル時間 4,811 ms
コンパイル使用メモリ 77,224 KB
実行使用メモリ 81,100 KB
最終ジャッジ日時 2023-09-18 03:39:36
合計ジャッジ時間 61,182 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 133 ms
55,684 KB
testcase_01 AC 130 ms
55,720 KB
testcase_02 AC 1,559 ms
81,100 KB
testcase_03 AC 1,353 ms
78,476 KB
testcase_04 AC 1,170 ms
70,792 KB
testcase_05 AC 764 ms
62,856 KB
testcase_06 AC 1,577 ms
78,292 KB
testcase_07 AC 1,593 ms
80,660 KB
testcase_08 AC 1,867 ms
80,680 KB
testcase_09 AC 1,507 ms
80,812 KB
testcase_10 AC 965 ms
70,684 KB
testcase_11 AC 1,035 ms
70,648 KB
testcase_12 AC 951 ms
70,584 KB
testcase_13 AC 772 ms
68,812 KB
testcase_14 AC 650 ms
64,900 KB
testcase_15 AC 921 ms
70,440 KB
testcase_16 AC 974 ms
70,516 KB
testcase_17 AC 336 ms
60,084 KB
testcase_18 AC 433 ms
60,464 KB
testcase_19 AC 1,061 ms
69,056 KB
testcase_20 AC 1,238 ms
75,800 KB
testcase_21 AC 1,245 ms
70,428 KB
testcase_22 AC 1,153 ms
78,580 KB
testcase_23 AC 1,077 ms
76,196 KB
testcase_24 AC 1,097 ms
75,596 KB
testcase_25 AC 1,191 ms
76,784 KB
testcase_26 AC 1,165 ms
76,632 KB
testcase_27 AC 707 ms
64,884 KB
testcase_28 AC 1,237 ms
80,764 KB
testcase_29 AC 1,105 ms
70,996 KB
testcase_30 AC 1,265 ms
75,920 KB
testcase_31 AC 1,314 ms
80,872 KB
testcase_32 AC 1,394 ms
78,516 KB
testcase_33 AC 1,083 ms
75,224 KB
testcase_34 AC 708 ms
68,808 KB
testcase_35 AC 924 ms
69,072 KB
testcase_36 AC 1,017 ms
70,548 KB
testcase_37 AC 1,049 ms
74,548 KB
testcase_38 AC 469 ms
60,596 KB
testcase_39 AC 989 ms
70,628 KB
testcase_40 AC 983 ms
70,448 KB
testcase_41 AC 905 ms
70,704 KB
testcase_42 AC 904 ms
70,052 KB
testcase_43 AC 1,072 ms
78,500 KB
testcase_44 AC 1,080 ms
79,280 KB
testcase_45 AC 1,075 ms
78,424 KB
testcase_46 TLE -
testcase_47 -- -
testcase_48 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

package yukicoder;

import java.util.Scanner;
import java.util.List;
import java.util.ArrayList;
import java.util.stream.Collectors;

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();
		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);
						}
					}
				}
			}
			if (newfw.isEmpty()) {
				depth = 0;
				break;
			}
			fw = newfw;
			depth++;
		}
		return depth;
	}
}
0