結果

問題 No.1065 電柱 / Pole (Easy)
ユーザー yuma220284yuma220284
提出日時 2020-05-29 21:30:45
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 360 ms / 2,000 ms
コード長 1,350 bytes
コンパイル時間 1,538 ms
コンパイル使用メモリ 174,224 KB
実行使用メモリ 36,160 KB
最終ジャッジ日時 2024-04-23 20:18:52
合計ジャッジ時間 8,642 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,816 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 169 ms
19,840 KB
testcase_03 AC 238 ms
34,300 KB
testcase_04 AC 242 ms
33,116 KB
testcase_05 AC 202 ms
33,488 KB
testcase_06 AC 201 ms
33,916 KB
testcase_07 AC 73 ms
11,904 KB
testcase_08 AC 273 ms
35,532 KB
testcase_09 AC 25 ms
6,940 KB
testcase_10 AC 126 ms
17,664 KB
testcase_11 AC 84 ms
13,184 KB
testcase_12 AC 45 ms
10,112 KB
testcase_13 AC 161 ms
21,912 KB
testcase_14 AC 183 ms
25,548 KB
testcase_15 AC 214 ms
28,572 KB
testcase_16 AC 103 ms
16,368 KB
testcase_17 AC 246 ms
30,708 KB
testcase_18 AC 71 ms
12,672 KB
testcase_19 AC 231 ms
29,312 KB
testcase_20 AC 60 ms
10,620 KB
testcase_21 AC 85 ms
14,848 KB
testcase_22 AC 201 ms
26,928 KB
testcase_23 AC 4 ms
6,944 KB
testcase_24 AC 4 ms
6,940 KB
testcase_25 AC 41 ms
9,600 KB
testcase_26 AC 120 ms
18,344 KB
testcase_27 AC 122 ms
17,988 KB
testcase_28 AC 206 ms
27,348 KB
testcase_29 AC 24 ms
7,296 KB
testcase_30 AC 222 ms
29,868 KB
testcase_31 AC 154 ms
23,196 KB
testcase_32 AC 104 ms
15,928 KB
testcase_33 AC 224 ms
30,556 KB
testcase_34 AC 81 ms
13,184 KB
testcase_35 AC 239 ms
30,332 KB
testcase_36 AC 3 ms
6,944 KB
testcase_37 AC 4 ms
6,940 KB
testcase_38 AC 3 ms
6,940 KB
testcase_39 AC 4 ms
6,944 KB
testcase_40 AC 2 ms
6,940 KB
testcase_41 AC 360 ms
36,160 KB
testcase_42 AC 101 ms
13,440 KB
testcase_43 AC 171 ms
20,736 KB
testcase_44 AC 59 ms
9,728 KB
testcase_45 AC 165 ms
20,224 KB
testcase_46 AC 2 ms
6,940 KB
testcase_47 AC 2 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"
using namespace std;

template<typename Type>
vector<Type> Dijkstra(vector<vector<pair<long long, Type> > > Graph, long long Start) {
	using PT = pair<Type, long long>;
	const Type Inf = numeric_limits<Type>::max();
	long long Size = Graph.size();
	vector<Type> Dist;
	Dist.assign(Size, Inf);
	priority_queue<PT, vector<PT>, greater<PT> > PQ;

	Dist[Start] = 0;
	PQ.emplace(PT(Dist[Start], Start));
	while (!PQ.empty()) {
		PT p = PQ.top();
		PQ.pop();
		Type D = p.first;
		long long E = p.second;
		if (Dist[E] < D) continue;
		for (pair<long long, Type> Next : Graph[E]) {
			Type ND = Next.second;
			long long NE = Next.first;
			if (Dist[NE] > Dist[E] + ND) {
				Dist[NE] = Dist[E] + ND;
				PQ.emplace(PT(Dist[NE], NE));
			}
		}
	}
	return Dist;
}

int main() {
	int N, M, X, Y;
	cin >> N >> M >> X >> Y;
	X--, Y--;
	vector<pair<double, double> > P(N);
	vector<vector<pair<long long, double> > > V(N);
	for (int i = 0; i < N; i++) {
		cin >> P[i].first >> P[i].second;
	}
	for (int i = 0; i < M; i++) {
		int S, T;
		cin >> S >> T;
		S--, T--;
		double D = (P[S].first - P[T].first) * (P[S].first - P[T].first) + (P[S].second - P[T].second) * (P[S].second - P[T].second);
		D = sqrt(D);
		V[S].push_back({ T, D });
		V[T].push_back({ S, D });
	}
	vector<double> Dist = Dijkstra(V, X);
	printf("%.12lf\n", Dist[Y]);
}
0