結果

問題 No.1473 おでぶなおばけさん
ユーザー 小野寺健小野寺健
提出日時 2021-04-26 13:38:31
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,297 bytes
コンパイル時間 735 ms
コンパイル使用メモリ 78,268 KB
実行使用メモリ 9,688 KB
最終ジャッジ日時 2023-09-18 06:13:22
合計ジャッジ時間 11,042 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
5,708 KB
testcase_01 AC 3 ms
5,708 KB
testcase_02 AC 179 ms
9,688 KB
testcase_03 AC 137 ms
9,004 KB
testcase_04 AC 103 ms
7,720 KB
testcase_05 AC 43 ms
6,496 KB
testcase_06 AC 187 ms
9,556 KB
testcase_07 AC 179 ms
9,468 KB
testcase_08 AC 231 ms
9,540 KB
testcase_09 AC 169 ms
9,516 KB
testcase_10 AC 84 ms
7,652 KB
testcase_11 AC 104 ms
8,528 KB
testcase_12 AC 84 ms
7,916 KB
testcase_13 AC 52 ms
6,964 KB
testcase_14 AC 38 ms
6,484 KB
testcase_15 AC 73 ms
7,748 KB
testcase_16 AC 83 ms
7,424 KB
testcase_17 AC 9 ms
5,960 KB
testcase_18 AC 14 ms
6,104 KB
testcase_19 AC 84 ms
8,276 KB
testcase_20 AC 101 ms
8,844 KB
testcase_21 AC 150 ms
8,804 KB
testcase_22 AC 98 ms
9,164 KB
testcase_23 AC 81 ms
8,752 KB
testcase_24 AC 84 ms
8,652 KB
testcase_25 AC 120 ms
9,204 KB
testcase_26 AC 124 ms
9,140 KB
testcase_27 AC 49 ms
7,116 KB
testcase_28 AC 128 ms
9,404 KB
testcase_29 AC 109 ms
8,776 KB
testcase_30 AC 132 ms
9,092 KB
testcase_31 AC 135 ms
9,500 KB
testcase_32 AC 151 ms
9,412 KB
testcase_33 AC 96 ms
8,752 KB
testcase_34 AC 47 ms
7,316 KB
testcase_35 AC 64 ms
7,580 KB
testcase_36 AC 94 ms
8,604 KB
testcase_37 AC 89 ms
8,644 KB
testcase_38 AC 21 ms
6,336 KB
testcase_39 AC 83 ms
7,776 KB
testcase_40 AC 84 ms
7,564 KB
testcase_41 AC 73 ms
7,192 KB
testcase_42 AC 73 ms
7,280 KB
testcase_43 AC 95 ms
8,244 KB
testcase_44 AC 94 ms
8,428 KB
testcase_45 AC 94 ms
8,252 KB
testcase_46 TLE -
testcase_47 -- -
testcase_48 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <vector>
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;

#define MAX_N 100000

struct Q {
	int i, d;
};

int n;
vector<Q> V[MAX_N];

int bfs(int w) {
	bool B[n];
	for (int i=0; i < n ; i++) B[i] = false;
	vector<int> fw;
	fw.push_back(0);
	int depth = 1;
	while (true) {
		vector<int> newfw;
		for (int i = 0; i < fw.size(); i++) {
			int j = fw[i];
			B[j] = true;
			for (int k = 0; k < V[j].size(); k++) {
				Q q = V[j][k];
				if (q.d >= w) {
					if (q.i == n - 1) {
						return depth;
					}
					if (!B[q.i]) {
						newfw.push_back(q.i);
					}
				}
			}
		}
		if (newfw.size() == 0) {
			depth = 0;
			break;
		}
		fw = newfw;
		depth++;
	}
	return depth;
}

int main() {
	int m;
	cin >> n >> m;
	for (int i=0; i < n; i++) {
		V[i] = vector<Q>();
	}
	int max_d = 0;
	int min_d = 0x7fffffff;
	for (int i=0; i < m; i++) {
		int s, t, d;
		std::cin >> s >> t >> d;
		V[s-1].push_back(Q{t-1, d});
		V[t-1].push_back(Q{s-1, d});
		max_d = max_d > d ? max_d : d;
		min_d = min_d < d ? min_d : d;
	}
	Q l = Q{min_d - 1, 0};
	Q r = 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;
		}
	}
	std::cout << l.i << ' ' << l.d << endl;
}
0