結果

問題 No.1473 おでぶなおばけさん
ユーザー 小野寺健小野寺健
提出日時 2021-04-26 08:53:50
言語 Java21
(openjdk 21)
結果
TLE  
実行時間 -
コード長 1,552 bytes
コンパイル時間 4,639 ms
コンパイル使用メモリ 79,872 KB
実行使用メモリ 619,180 KB
最終ジャッジ日時 2023-09-18 00:21:32
合計ジャッジ時間 62,404 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 128 ms
59,980 KB
testcase_01 AC 125 ms
54,440 KB
testcase_02 TLE -
testcase_03 AC 1,362 ms
78,764 KB
testcase_04 AC 1,314 ms
71,116 KB
testcase_05 AC 899 ms
67,124 KB
testcase_06 AC 1,824 ms
79,220 KB
testcase_07 AC 1,689 ms
80,916 KB
testcase_08 TLE -
testcase_09 AC 1,567 ms
80,964 KB
testcase_10 AC 1,104 ms
70,556 KB
testcase_11 AC 1,244 ms
71,952 KB
testcase_12 AC 1,136 ms
72,652 KB
testcase_13 AC 862 ms
69,376 KB
testcase_14 AC 690 ms
66,360 KB
testcase_15 AC 1,054 ms
70,620 KB
testcase_16 AC 1,157 ms
71,152 KB
testcase_17 AC 341 ms
60,372 KB
testcase_18 AC 442 ms
60,532 KB
testcase_19 AC 1,183 ms
70,732 KB
testcase_20 AC 1,251 ms
76,420 KB
testcase_21 TLE -
testcase_22 AC 1,356 ms
78,424 KB
testcase_23 AC 1,134 ms
74,480 KB
testcase_24 AC 1,267 ms
75,540 KB
testcase_25 AC 1,279 ms
76,500 KB
testcase_26 AC 1,202 ms
76,756 KB
testcase_27 AC 870 ms
69,420 KB
testcase_28 AC 1,240 ms
81,080 KB
testcase_29 AC 1,218 ms
71,196 KB
testcase_30 AC 1,401 ms
76,220 KB
testcase_31 AC 1,593 ms
80,724 KB
testcase_32 AC 1,528 ms
78,528 KB
testcase_33 AC 1,169 ms
75,612 KB
testcase_34 AC 777 ms
69,028 KB
testcase_35 AC 1,063 ms
67,000 KB
testcase_36 AC 1,963 ms
74,332 KB
testcase_37 AC 1,095 ms
74,704 KB
testcase_38 AC 489 ms
60,884 KB
testcase_39 AC 1,174 ms
72,136 KB
testcase_40 AC 1,117 ms
70,308 KB
testcase_41 AC 1,037 ms
70,896 KB
testcase_42 AC 1,033 ms
70,700 KB
testcase_43 MLE -
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 class Q {
		public int i;
		public long d;
		public Q(int i, long 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>());
		}
		long max_d = 0;
		long min_d = Long.MAX_VALUE;
		for (int i=0; i < m; i++) {
			int s = scan.nextInt() - 1;
			int t = scan.nextInt() - 1;
			long d = scan.nextLong();
			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(0, min_d - 1), r = new Q(0, max_d + 1);
		while (r.d - l.d > 1) {
			long mid = (r.d + l.d) / 2;
			int c = bfs(mid);
			if (c == 0) {
				r.d = mid;
				r.i = 0;
			} else {
				l.d = mid;
				l.i = c;
			}
		}
		System.out.println(String.format("%d %d", l.d,l.i));
	}
	
	private static int bfs(long 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 (Q i : V.get(v[0])) {
				if (i.d >= w && !B[i.i]) {
					q.add(new Integer[] {i.i, v[1] + 1});
				}
			}
		}
		return 0;
	}

}
0