結果

問題 No.1473 おでぶなおばけさん
ユーザー 小野寺健小野寺健
提出日時 2021-04-26 10:21:54
言語 Java21
(openjdk 21)
結果
TLE  
実行時間 -
コード長 2,072 bytes
コンパイル時間 3,567 ms
コンパイル使用メモリ 74,504 KB
実行使用メモリ 340,392 KB
最終ジャッジ日時 2023-09-18 02:03:23
合計ジャッジ時間 58,391 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 130 ms
55,388 KB
testcase_01 AC 131 ms
55,832 KB
testcase_02 AC 1,457 ms
89,884 KB
testcase_03 AC 1,407 ms
86,608 KB
testcase_04 AC 1,058 ms
77,108 KB
testcase_05 AC 597 ms
62,936 KB
testcase_06 AC 1,324 ms
83,448 KB
testcase_07 AC 1,864 ms
97,268 KB
testcase_08 TLE -
testcase_09 AC 1,752 ms
87,884 KB
testcase_10 AC 975 ms
71,572 KB
testcase_11 AC 997 ms
71,428 KB
testcase_12 AC 1,011 ms
71,108 KB
testcase_13 AC 805 ms
68,980 KB
testcase_14 AC 660 ms
65,908 KB
testcase_15 AC 1,013 ms
70,788 KB
testcase_16 AC 951 ms
70,896 KB
testcase_17 AC 322 ms
60,132 KB
testcase_18 AC 415 ms
60,236 KB
testcase_19 AC 903 ms
68,908 KB
testcase_20 AC 1,155 ms
79,324 KB
testcase_21 AC 1,027 ms
70,708 KB
testcase_22 AC 1,067 ms
78,756 KB
testcase_23 AC 1,008 ms
76,504 KB
testcase_24 AC 1,014 ms
75,796 KB
testcase_25 AC 1,136 ms
76,400 KB
testcase_26 AC 1,158 ms
76,156 KB
testcase_27 AC 711 ms
66,024 KB
testcase_28 AC 1,341 ms
84,300 KB
testcase_29 AC 1,055 ms
72,192 KB
testcase_30 AC 1,166 ms
75,976 KB
testcase_31 AC 1,254 ms
87,112 KB
testcase_32 AC 1,309 ms
81,748 KB
testcase_33 AC 1,069 ms
76,112 KB
testcase_34 AC 744 ms
69,104 KB
testcase_35 AC 817 ms
69,376 KB
testcase_36 AC 948 ms
70,332 KB
testcase_37 AC 1,027 ms
75,356 KB
testcase_38 AC 474 ms
58,764 KB
testcase_39 AC 998 ms
71,120 KB
testcase_40 AC 1,002 ms
71,296 KB
testcase_41 AC 995 ms
70,456 KB
testcase_42 AC 1,017 ms
70,600 KB
testcase_43 AC 1,247 ms
83,296 KB
testcase_44 AC 1,263 ms
83,168 KB
testcase_45 AC 1,221 ms
82,552 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;
				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);
						}
					}
				}
			}
			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);
						}
					}
				}
			}
			if (newbw.isEmpty()) {
				depth = 0;
				break;
			}
			bw = newbw;
			depth++;
		}
		return depth;
	}

}
0