結果

問題 No.1473 おでぶなおばけさん
ユーザー 小野寺健小野寺健
提出日時 2021-04-26 13:33:32
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,282 bytes
コンパイル時間 867 ms
コンパイル使用メモリ 81,104 KB
実行使用メモリ 356,644 KB
最終ジャッジ日時 2023-09-18 06:04:56
合計ジャッジ時間 10,670 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
8,756 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 181 ms
9,076 KB
testcase_03 AC 136 ms
8,120 KB
testcase_04 AC 101 ms
6,160 KB
testcase_05 AC 42 ms
4,376 KB
testcase_06 AC 184 ms
8,348 KB
testcase_07 AC 173 ms
9,124 KB
testcase_08 AC 223 ms
9,228 KB
testcase_09 AC 167 ms
9,060 KB
testcase_10 AC 81 ms
5,596 KB
testcase_11 AC 93 ms
6,260 KB
testcase_12 AC 81 ms
5,884 KB
testcase_13 AC 50 ms
4,624 KB
testcase_14 AC 36 ms
4,376 KB
testcase_15 AC 70 ms
5,532 KB
testcase_16 AC 79 ms
5,012 KB
testcase_17 AC 7 ms
4,376 KB
testcase_18 AC 11 ms
4,376 KB
testcase_19 AC 79 ms
5,692 KB
testcase_20 AC 101 ms
7,548 KB
testcase_21 AC 145 ms
7,132 KB
testcase_22 AC 101 ms
8,524 KB
testcase_23 AC 81 ms
7,812 KB
testcase_24 AC 82 ms
7,632 KB
testcase_25 AC 118 ms
8,204 KB
testcase_26 AC 123 ms
8,032 KB
testcase_27 AC 46 ms
4,844 KB
testcase_28 AC 126 ms
9,316 KB
testcase_29 AC 107 ms
7,084 KB
testcase_30 AC 129 ms
7,560 KB
testcase_31 AC 132 ms
8,992 KB
testcase_32 AC 147 ms
8,580 KB
testcase_33 AC 95 ms
7,576 KB
testcase_34 AC 45 ms
5,312 KB
testcase_35 AC 62 ms
5,520 KB
testcase_36 AC 97 ms
7,112 KB
testcase_37 AC 89 ms
7,284 KB
testcase_38 AC 18 ms
4,376 KB
testcase_39 AC 79 ms
5,284 KB
testcase_40 AC 81 ms
5,280 KB
testcase_41 AC 70 ms
4,852 KB
testcase_42 AC 68 ms
4,964 KB
testcase_43 AC 91 ms
6,908 KB
testcase_44 AC 91 ms
7,028 KB
testcase_45 AC 91 ms
6,952 KB
testcase_46 TLE -
testcase_47 -- -
testcase_48 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

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

struct Q {
	int i, d;
};

int n;
vector<vector<Q>> V;

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.push_back(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