結果

問題 No.1473 おでぶなおばけさん
ユーザー 小野寺健小野寺健
提出日時 2021-04-26 10:37:19
言語 Java21
(openjdk 21)
結果
TLE  
実行時間 -
コード長 2,202 bytes
コンパイル時間 4,184 ms
コンパイル使用メモリ 83,484 KB
実行使用メモリ 238,028 KB
最終ジャッジ日時 2023-09-18 02:20:37
合計ジャッジ時間 59,152 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 130 ms
57,192 KB
testcase_01 AC 129 ms
55,608 KB
testcase_02 AC 1,440 ms
90,276 KB
testcase_03 AC 1,413 ms
83,844 KB
testcase_04 AC 1,064 ms
76,968 KB
testcase_05 AC 624 ms
62,568 KB
testcase_06 AC 1,392 ms
83,308 KB
testcase_07 AC 1,991 ms
91,000 KB
testcase_08 TLE -
testcase_09 AC 1,906 ms
91,712 KB
testcase_10 AC 992 ms
70,920 KB
testcase_11 AC 1,054 ms
71,840 KB
testcase_12 AC 1,012 ms
70,872 KB
testcase_13 AC 839 ms
68,648 KB
testcase_14 AC 709 ms
67,220 KB
testcase_15 AC 1,028 ms
70,748 KB
testcase_16 AC 1,002 ms
70,676 KB
testcase_17 AC 346 ms
60,216 KB
testcase_18 AC 413 ms
60,056 KB
testcase_19 AC 931 ms
68,536 KB
testcase_20 AC 1,133 ms
78,832 KB
testcase_21 AC 988 ms
70,692 KB
testcase_22 AC 1,061 ms
78,504 KB
testcase_23 AC 981 ms
76,176 KB
testcase_24 AC 982 ms
75,572 KB
testcase_25 AC 1,086 ms
76,976 KB
testcase_26 AC 1,112 ms
76,348 KB
testcase_27 AC 690 ms
66,008 KB
testcase_28 AC 1,382 ms
84,256 KB
testcase_29 AC 991 ms
70,824 KB
testcase_30 AC 1,147 ms
76,180 KB
testcase_31 AC 1,259 ms
88,300 KB
testcase_32 AC 1,340 ms
79,032 KB
testcase_33 AC 1,058 ms
76,072 KB
testcase_34 AC 723 ms
69,024 KB
testcase_35 AC 792 ms
69,128 KB
testcase_36 AC 909 ms
70,668 KB
testcase_37 AC 984 ms
75,624 KB
testcase_38 AC 468 ms
60,296 KB
testcase_39 AC 1,023 ms
70,728 KB
testcase_40 AC 1,083 ms
70,824 KB
testcase_41 AC 1,363 ms
71,656 KB
testcase_42 AC 1,416 ms
72,040 KB
testcase_43 AC 1,324 ms
81,540 KB
testcase_44 AC 1,309 ms
84,132 KB
testcase_45 AC 1,242 ms
82,652 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();
		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;
				V.get(i).sort((a,b)-> b.d - a.d);
				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;
				V.get(i).sort((a,b)-> b.d - a.d);
				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