結果

問題 No.1069 電柱 / Pole (Hard)
ユーザー QCFiumQCFium
提出日時 2020-05-29 22:10:04
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 2,447 bytes
コンパイル時間 2,289 ms
コンパイル使用メモリ 185,656 KB
実行使用メモリ 6,988 KB
最終ジャッジ日時 2024-04-24 05:09:14
合計ジャッジ時間 42,781 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 815 ms
6,944 KB
testcase_05 AC 361 ms
6,988 KB
testcase_06 AC 1,795 ms
6,940 KB
testcase_07 AC 876 ms
6,944 KB
testcase_08 TLE -
testcase_09 AC 1,438 ms
6,940 KB
testcase_10 AC 294 ms
6,944 KB
testcase_11 AC 8 ms
6,944 KB
testcase_12 AC 377 ms
6,940 KB
testcase_13 AC 1,490 ms
6,940 KB
testcase_14 AC 651 ms
6,940 KB
testcase_15 AC 1,670 ms
6,940 KB
testcase_16 AC 235 ms
6,944 KB
testcase_17 AC 332 ms
6,940 KB
testcase_18 AC 679 ms
6,944 KB
testcase_19 TLE -
testcase_20 AC 793 ms
6,940 KB
testcase_21 AC 827 ms
6,940 KB
testcase_22 AC 459 ms
6,944 KB
testcase_23 AC 1,014 ms
6,940 KB
testcase_24 AC 229 ms
6,944 KB
testcase_25 AC 231 ms
6,944 KB
testcase_26 AC 167 ms
6,944 KB
testcase_27 AC 170 ms
6,940 KB
testcase_28 AC 168 ms
6,944 KB
testcase_29 AC 339 ms
6,944 KB
testcase_30 AC 53 ms
6,940 KB
testcase_31 AC 2 ms
6,940 KB
testcase_32 AC 2 ms
6,940 KB
testcase_33 AC 2 ms
6,940 KB
testcase_34 AC 2 ms
6,944 KB
testcase_35 AC 2 ms
6,940 KB
testcase_36 AC 3 ms
6,944 KB
testcase_37 AC 168 ms
6,940 KB
testcase_38 AC 141 ms
6,940 KB
testcase_39 AC 2 ms
6,944 KB
testcase_40 AC 77 ms
6,944 KB
testcase_41 AC 406 ms
6,940 KB
testcase_42 AC 146 ms
6,944 KB
testcase_43 AC 52 ms
6,944 KB
testcase_44 AC 907 ms
6,944 KB
testcase_45 AC 1,961 ms
6,940 KB
testcase_46 AC 1,691 ms
6,940 KB
testcase_47 AC 1,118 ms
6,940 KB
testcase_48 AC 141 ms
6,940 KB
testcase_49 AC 1,518 ms
6,944 KB
testcase_50 AC 161 ms
6,944 KB
testcase_51 AC 1,063 ms
6,944 KB
testcase_52 AC 225 ms
6,944 KB
testcase_53 AC 1,268 ms
6,940 KB
testcase_54 AC 2 ms
6,944 KB
testcase_55 AC 2 ms
6,940 KB
testcase_56 AC 2 ms
6,940 KB
testcase_57 AC 3 ms
6,940 KB
testcase_58 AC 2 ms
6,944 KB
testcase_59 AC 3 ms
6,940 KB
testcase_60 AC 2 ms
6,940 KB
testcase_61 AC 2 ms
6,940 KB
testcase_62 AC 2 ms
6,940 KB
testcase_63 AC 2 ms
6,944 KB
testcase_64 AC 3 ms
6,940 KB
testcase_65 AC 2 ms
6,944 KB
testcase_66 AC 2 ms
6,940 KB
testcase_67 AC 2 ms
6,940 KB
testcase_68 AC 2 ms
6,940 KB
testcase_69 AC 5 ms
6,944 KB
testcase_70 AC 7 ms
6,940 KB
testcase_71 AC 3 ms
6,940 KB
testcase_72 AC 3 ms
6,940 KB
testcase_73 AC 4 ms
6,940 KB
testcase_74 AC 7 ms
6,944 KB
testcase_75 AC 7 ms
6,940 KB
testcase_76 AC 244 ms
6,940 KB
testcase_77 AC 593 ms
6,940 KB
testcase_78 AC 6 ms
6,944 KB
testcase_79 AC 1,540 ms
6,944 KB
testcase_80 AC 695 ms
6,940 KB
testcase_81 AC 1,744 ms
6,940 KB
testcase_82 AC 1,566 ms
6,940 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.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