結果

問題 No.1069 電柱 / Pole (Hard)
ユーザー QCFiumQCFium
提出日時 2020-05-29 22:11:31
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,442 ms / 2,000 ms
コード長 2,485 bytes
コンパイル時間 1,925 ms
コンパイル使用メモリ 186,472 KB
実行使用メモリ 6,696 KB
最終ジャッジ日時 2023-09-30 21:18:05
合計ジャッジ時間 26,252 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 481 ms
6,600 KB
testcase_05 AC 359 ms
6,696 KB
testcase_06 AC 1,344 ms
5,052 KB
testcase_07 AC 757 ms
4,780 KB
testcase_08 AC 810 ms
6,164 KB
testcase_09 AC 914 ms
5,076 KB
testcase_10 AC 115 ms
4,380 KB
testcase_11 AC 7 ms
4,376 KB
testcase_12 AC 216 ms
4,376 KB
testcase_13 AC 1,036 ms
4,740 KB
testcase_14 AC 147 ms
5,792 KB
testcase_15 AC 982 ms
6,156 KB
testcase_16 AC 110 ms
4,380 KB
testcase_17 AC 190 ms
4,604 KB
testcase_18 AC 338 ms
4,604 KB
testcase_19 AC 1,442 ms
6,256 KB
testcase_20 AC 517 ms
5,756 KB
testcase_21 AC 382 ms
5,768 KB
testcase_22 AC 92 ms
5,624 KB
testcase_23 AC 568 ms
5,640 KB
testcase_24 AC 69 ms
4,376 KB
testcase_25 AC 216 ms
4,380 KB
testcase_26 AC 115 ms
4,376 KB
testcase_27 AC 171 ms
4,384 KB
testcase_28 AC 123 ms
4,384 KB
testcase_29 AC 242 ms
4,376 KB
testcase_30 AC 36 ms
4,380 KB
testcase_31 AC 2 ms
4,376 KB
testcase_32 AC 2 ms
4,376 KB
testcase_33 AC 1 ms
4,380 KB
testcase_34 AC 1 ms
4,380 KB
testcase_35 AC 1 ms
4,384 KB
testcase_36 AC 2 ms
4,376 KB
testcase_37 AC 139 ms
4,380 KB
testcase_38 AC 76 ms
4,376 KB
testcase_39 AC 2 ms
4,380 KB
testcase_40 AC 43 ms
4,380 KB
testcase_41 AC 194 ms
4,620 KB
testcase_42 AC 97 ms
4,380 KB
testcase_43 AC 32 ms
4,376 KB
testcase_44 AC 674 ms
4,648 KB
testcase_45 AC 1,014 ms
5,472 KB
testcase_46 AC 797 ms
5,888 KB
testcase_47 AC 484 ms
5,288 KB
testcase_48 AC 128 ms
4,376 KB
testcase_49 AC 665 ms
5,020 KB
testcase_50 AC 79 ms
4,376 KB
testcase_51 AC 515 ms
4,784 KB
testcase_52 AC 123 ms
4,376 KB
testcase_53 AC 699 ms
4,856 KB
testcase_54 AC 2 ms
4,376 KB
testcase_55 AC 2 ms
4,380 KB
testcase_56 AC 2 ms
4,376 KB
testcase_57 AC 2 ms
4,380 KB
testcase_58 AC 1 ms
4,380 KB
testcase_59 AC 3 ms
4,376 KB
testcase_60 AC 1 ms
4,376 KB
testcase_61 AC 2 ms
4,376 KB
testcase_62 AC 2 ms
4,376 KB
testcase_63 AC 1 ms
4,380 KB
testcase_64 AC 2 ms
4,380 KB
testcase_65 AC 2 ms
4,376 KB
testcase_66 AC 2 ms
4,380 KB
testcase_67 AC 1 ms
4,380 KB
testcase_68 AC 2 ms
4,376 KB
testcase_69 AC 4 ms
4,376 KB
testcase_70 AC 4 ms
4,376 KB
testcase_71 AC 3 ms
4,376 KB
testcase_72 AC 2 ms
4,380 KB
testcase_73 AC 3 ms
4,376 KB
testcase_74 AC 4 ms
4,380 KB
testcase_75 AC 3 ms
4,376 KB
testcase_76 AC 141 ms
4,376 KB
testcase_77 AC 425 ms
4,728 KB
testcase_78 AC 5 ms
4,376 KB
testcase_79 AC 997 ms
5,680 KB
testcase_80 AC 686 ms
4,888 KB
testcase_81 AC 493 ms
6,124 KB
testcase_82 AC 1,442 ms
6,420 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

int ri() {
	int n;
	scanf("%d", &n);
	return n;
}

template<typename T> using pqueue_inv = std::priority_queue<T, std::vector<T>, std::greater<T> >;

const double DINF = 1000000000;

int main() {
	int n = ri();
	int m = ri();
	int k = ri();
	int x = ri() - 1, y = ri() - 1;
	std::pair<int, int> pts[n];
	for (auto &i : pts) i.first = ri(), i.second = ri();
	auto calc_dist = [&] (int i, int j) {
		return std::hypot(pts[i].first - pts[j].first, pts[i].second - pts[j].second);
	};
	
	std::vector<std::pair<int, double> > hen[n];
	for (int i = 0; i < m; i++) {
		int x = ri() - 1;
		int y = ri() - 1;
		hen[x].push_back({y, calc_dist(x, y)});
		hen[y].push_back({x, calc_dist(x, y)});
	}
	
	struct Payload {
		double cur_cost;
		int pos;
		std::vector<bool> used;
		bool operator > (const Payload &rhs) const {
			return cur_cost > rhs.cur_cost;
		}
		bool operator < (const Payload &rhs) const {
			return cur_cost < rhs.cur_cost;
		}
	};
	auto dijkstra = [&] (int s, int t, const std::vector<bool> &used) {
		std::vector<double> dist(n, DINF);
		pqueue_inv<std::pair<double, int> > que;
		que.push({dist[s] = 0, s});
		while (que.size()) {
			auto j = que.top();
			que.pop();
			if (j.second == t) return dist[t];
			if (j.first != dist[j.second]) continue;
			for (auto k : hen[j.second]) {
				if (used[k.first]) continue;
				if (dist[k.first] > j.first + k.second) que.push({dist[k.first] = j.first + k.second, k.first});
			}
		}
		return dist[t];
	};
	if (dijkstra(x, y, std::vector<bool>(n)) == DINF) {
		for (int i = 0; i < k; i++) puts("-1");
		return 0;
	}
	
	pqueue_inv<std::pair<double, Payload> > que;
	std::vector<std::pair<double, Payload> > all[n];
	std::vector<bool> init_(n);
	init_[x] = true;
	que.push({dijkstra(x, y, std::vector<bool>(n)), {0, x, init_}});
	while (que.size()) {
		auto i = que.top();
		que.pop();
		double cur_cost = i.second.cur_cost;
		int x = i.second.pos;
		auto &used = i.second.used;
		if ((int) all[x].size() >= k) continue;
		all[x].push_back(i);
		for (auto j : hen[x]) {
			if (used[j.first]) continue;
			used[j.first] = true;
			double cost = dijkstra(j.first, y, used);
			if (cost == DINF) continue;
			double new_estimated = cost + cur_cost + j.second;
			que.push({new_estimated, {cur_cost + j.second, j.first, used}});
			// bfs
			used[j.first] = false;
		}
	}
	for (int i = 0; i < k; i++) {
		if (i < (int) all[y].size()) {
			printf("%.11f\n", all[y][i].first);
		} else puts("-1");
	}
	return 0;
}
0