結果

問題 No.1065 電柱 / Pole (Easy)
ユーザー oriekaorieka
提出日時 2020-05-30 10:07:59
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 373 ms / 2,000 ms
コード長 1,195 bytes
コンパイル時間 1,326 ms
コンパイル使用メモリ 112,120 KB
実行使用メモリ 17,280 KB
最終ジャッジ日時 2024-04-24 20:02:58
合計ジャッジ時間 10,486 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 169 ms
10,624 KB
testcase_03 AC 231 ms
15,628 KB
testcase_04 AC 233 ms
15,628 KB
testcase_05 AC 189 ms
15,624 KB
testcase_06 AC 188 ms
15,628 KB
testcase_07 AC 65 ms
7,168 KB
testcase_08 AC 244 ms
17,280 KB
testcase_09 AC 23 ms
5,376 KB
testcase_10 AC 107 ms
9,472 KB
testcase_11 AC 74 ms
7,808 KB
testcase_12 AC 45 ms
5,376 KB
testcase_13 AC 158 ms
10,224 KB
testcase_14 AC 192 ms
13,020 KB
testcase_15 AC 221 ms
14,472 KB
testcase_16 AC 105 ms
7,568 KB
testcase_17 AC 240 ms
15,144 KB
testcase_18 AC 73 ms
6,144 KB
testcase_19 AC 231 ms
15,188 KB
testcase_20 AC 57 ms
6,656 KB
testcase_21 AC 89 ms
6,272 KB
testcase_22 AC 209 ms
13,624 KB
testcase_23 AC 4 ms
5,376 KB
testcase_24 AC 4 ms
5,376 KB
testcase_25 AC 41 ms
5,376 KB
testcase_26 AC 118 ms
9,700 KB
testcase_27 AC 119 ms
8,688 KB
testcase_28 AC 211 ms
12,600 KB
testcase_29 AC 25 ms
5,376 KB
testcase_30 AC 226 ms
14,616 KB
testcase_31 AC 154 ms
12,444 KB
testcase_32 AC 101 ms
8,888 KB
testcase_33 AC 230 ms
16,604 KB
testcase_34 AC 77 ms
6,612 KB
testcase_35 AC 231 ms
14,468 KB
testcase_36 AC 3 ms
5,376 KB
testcase_37 AC 4 ms
5,376 KB
testcase_38 AC 3 ms
5,376 KB
testcase_39 AC 4 ms
5,376 KB
testcase_40 AC 3 ms
5,376 KB
testcase_41 AC 373 ms
17,152 KB
testcase_42 AC 99 ms
7,936 KB
testcase_43 AC 178 ms
10,880 KB
testcase_44 AC 59 ms
6,272 KB
testcase_45 AC 176 ms
10,752 KB
testcase_46 AC 2 ms
5,376 KB
testcase_47 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <climits>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <bitset>
#include <utility>
#include <numeric>
#include <queue>
#include <stack>

using ll = long long;
using namespace std;

constexpr int MOD = 1e9 + 7;
constexpr ll MOD_LL = ll(1e9) + 7;

int main(void) {
	int n, m, x, y;
	cin >> n >> m >> x >> y;
	
	x--; y--;
	vector<int> p(n), q(n);
	for(int i = 0; i < n; ++i) {
		cin >> p[i] >> q[i];
	}
	
	vector< vector<int> > G(n);
	for(int i = 0; i < m; ++i) {
		int a, b;
		cin >> a >> b;
		a--; b--;
		
		G[a].push_back(b);
		G[b].push_back(a);
	}
	
	vector<double> dist(n, 1e9 + 10);
	dist[x] = 0.0;
	
	priority_queue< pair<double, int> > que;
	que.push( {0.0, x} );
	
	while( !que.empty() ) {
		double now_cost = -que.top().first;
		int now = que.top().second;
		que.pop();
		
		if( dist[now] != now_cost ) continue;
		
		for(auto &to : G[now]) {
			double cost = now_cost + sqrt((p[now] - p[to]) * (p[now] - p[to]) + (q[now] - q[to]) * (q[now] - q[to]));
			
			if( dist[to] > cost ) {
				dist[to] = cost;
				que.push( {-cost, to} );
			}
		}
	}

	printf("%.12f\n", dist[y]);
	
	return 0;
}
0