結果

問題 No.1473 おでぶなおばけさん
ユーザー 小野寺健小野寺健
提出日時 2021-04-26 11:05:31
言語 Java21
(openjdk 21)
結果
TLE  
実行時間 -
コード長 2,174 bytes
コンパイル時間 4,488 ms
コンパイル使用メモリ 79,580 KB
実行使用メモリ 110,012 KB
最終ジャッジ日時 2023-09-18 02:52:26
合計ジャッジ時間 17,484 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 139 ms
60,600 KB
testcase_01 AC 139 ms
56,072 KB
testcase_02 TLE -
testcase_03 TLE -
testcase_04 AC 1,427 ms
80,060 KB
testcase_05 AC 765 ms
65,164 KB
testcase_06 AC 1,739 ms
86,616 KB
testcase_07 TLE -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
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;
import java.util.stream.Collectors;

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).parallelStream().filter(q -> q.d >= w).collect(Collectors.toList())) {
					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).parallelStream().filter(q -> q.d >= w).collect(Collectors.toList())) {
					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