結果

問題 No.1473 おでぶなおばけさん
ユーザー 小野寺健小野寺健
提出日時 2021-04-26 10:33:26
言語 Java21
(openjdk 21)
結果
TLE  
実行時間 -
コード長 2,197 bytes
コンパイル時間 3,789 ms
コンパイル使用メモリ 77,372 KB
実行使用メモリ 99,576 KB
最終ジャッジ日時 2023-09-18 02:16:13
合計ジャッジ時間 59,878 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 127 ms
55,724 KB
testcase_01 AC 126 ms
55,656 KB
testcase_02 AC 1,445 ms
89,004 KB
testcase_03 AC 1,338 ms
81,216 KB
testcase_04 AC 1,059 ms
75,712 KB
testcase_05 AC 615 ms
62,848 KB
testcase_06 AC 1,353 ms
81,764 KB
testcase_07 AC 1,846 ms
95,556 KB
testcase_08 TLE -
testcase_09 AC 1,789 ms
94,252 KB
testcase_10 AC 1,046 ms
70,976 KB
testcase_11 AC 1,057 ms
71,716 KB
testcase_12 AC 1,103 ms
70,660 KB
testcase_13 AC 861 ms
68,792 KB
testcase_14 AC 736 ms
66,872 KB
testcase_15 AC 1,001 ms
70,584 KB
testcase_16 AC 1,013 ms
70,828 KB
testcase_17 AC 340 ms
60,424 KB
testcase_18 AC 429 ms
60,144 KB
testcase_19 AC 880 ms
68,672 KB
testcase_20 AC 1,151 ms
78,968 KB
testcase_21 AC 1,057 ms
70,816 KB
testcase_22 AC 1,048 ms
78,588 KB
testcase_23 AC 983 ms
76,040 KB
testcase_24 AC 1,030 ms
76,368 KB
testcase_25 AC 1,122 ms
76,324 KB
testcase_26 AC 1,141 ms
76,748 KB
testcase_27 AC 703 ms
66,712 KB
testcase_28 AC 1,328 ms
83,944 KB
testcase_29 AC 1,098 ms
70,348 KB
testcase_30 AC 1,151 ms
75,712 KB
testcase_31 AC 1,250 ms
82,972 KB
testcase_32 AC 1,278 ms
81,172 KB
testcase_33 AC 1,056 ms
78,512 KB
testcase_34 AC 766 ms
68,580 KB
testcase_35 AC 806 ms
68,948 KB
testcase_36 AC 953 ms
70,404 KB
testcase_37 AC 1,047 ms
74,660 KB
testcase_38 AC 466 ms
60,668 KB
testcase_39 AC 1,049 ms
71,204 KB
testcase_40 AC 1,007 ms
70,856 KB
testcase_41 AC 1,109 ms
70,796 KB
testcase_42 AC 1,103 ms
70,812 KB
testcase_43 AC 1,179 ms
80,824 KB
testcase_44 AC 1,164 ms
82,228 KB
testcase_45 AC 1,212 ms
83,360 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][2];
		List<Integer> fw = new ArrayList<Integer>();
		List<Integer> bw = new ArrayList<Integer>();
		fw.add(0);
		bw.add(n-1);
		int depth = 0;
		while (true) {
			List<Integer> newfw = new ArrayList<Integer>();
			for (int i : fw) {
				B[i][0] = true;
				for (Q n : V.get(i)) {
					if (n.d >= w ) {
						if (B[n.i][1]) {
							return depth;
						}
						if (!B[n.i][0]) {
							newfw.add(n.i);
						}
					} else {
						break;
					}
				}
			}
			if (newfw.isEmpty()) {
				depth = 0;
				break;
			}
			fw = newfw;
			depth++;
			List<Integer> newbw = new ArrayList<Integer>();
			for (int i : bw) {
				B[i][1] = true;
				for (Q n : V.get(i)) {
					if (n.d >= w ) {
						if (B[n.i][0]) {
							return depth;
						}
						if (!B[n.i][1]) {
							newbw.add(n.i);
						}
					} else {
						break;
					}
				}
			}
			if (newbw.isEmpty()) {
				depth = 0;
				break;
			}
			bw = newbw;
			depth++;
		}
		return depth;
	}

}
0