結果

問題 No.1473 おでぶなおばけさん
ユーザー 小野寺健小野寺健
提出日時 2021-04-26 09:12:29
言語 Java21
(openjdk 21)
結果
TLE  
実行時間 -
コード長 1,487 bytes
コンパイル時間 3,889 ms
コンパイル使用メモリ 74,416 KB
実行使用メモリ 461,272 KB
最終ジャッジ日時 2023-09-18 00:46:17
合計ジャッジ時間 57,592 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 130 ms
62,660 KB
testcase_01 AC 132 ms
55,536 KB
testcase_02 AC 1,887 ms
80,776 KB
testcase_03 AC 1,333 ms
76,732 KB
testcase_04 AC 1,196 ms
71,208 KB
testcase_05 AC 886 ms
67,080 KB
testcase_06 AC 1,680 ms
78,932 KB
testcase_07 AC 1,592 ms
80,564 KB
testcase_08 AC 1,953 ms
80,732 KB
testcase_09 AC 1,547 ms
80,464 KB
testcase_10 AC 1,036 ms
72,584 KB
testcase_11 AC 1,173 ms
71,944 KB
testcase_12 AC 1,048 ms
70,740 KB
testcase_13 AC 858 ms
68,924 KB
testcase_14 AC 697 ms
67,168 KB
testcase_15 AC 931 ms
70,864 KB
testcase_16 AC 994 ms
70,436 KB
testcase_17 AC 340 ms
60,296 KB
testcase_18 AC 446 ms
60,132 KB
testcase_19 AC 1,114 ms
69,340 KB
testcase_20 AC 1,171 ms
75,732 KB
testcase_21 AC 1,858 ms
70,248 KB
testcase_22 AC 1,318 ms
78,624 KB
testcase_23 AC 1,063 ms
76,332 KB
testcase_24 AC 1,240 ms
75,756 KB
testcase_25 AC 1,276 ms
76,312 KB
testcase_26 AC 1,171 ms
76,268 KB
testcase_27 AC 822 ms
67,104 KB
testcase_28 AC 1,195 ms
80,612 KB
testcase_29 AC 1,151 ms
70,828 KB
testcase_30 AC 1,337 ms
75,820 KB
testcase_31 AC 1,528 ms
80,560 KB
testcase_32 AC 1,416 ms
79,008 KB
testcase_33 AC 1,096 ms
75,360 KB
testcase_34 AC 754 ms
69,236 KB
testcase_35 AC 1,014 ms
69,020 KB
testcase_36 AC 1,748 ms
72,448 KB
testcase_37 AC 1,041 ms
75,464 KB
testcase_38 AC 458 ms
60,892 KB
testcase_39 AC 1,052 ms
70,468 KB
testcase_40 AC 1,013 ms
70,804 KB
testcase_41 AC 916 ms
70,576 KB
testcase_42 AC 949 ms
70,740 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 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<Q> q = new ArrayList<Q>();
		q.add(new Q(0, 0));
		B[0] = true;
		while (q.size() > 0) {
			Q v = q.remove(0);
			if (v.i == n-1) {
				return v.d;
			}
			B[v.i] = true;
			for (Q i : V.get(v.i)) {
				if (i.d >= w && !B[i.i]) {
					q.add(new Q (i.i, v.d + 1));
				}
			}
		}
		return 0;
	}

}
0