結果

問題 No.1065 電柱 / Pole (Easy)
ユーザー 沙耶花沙耶花
提出日時 2020-05-29 21:41:14
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 327 ms / 2,000 ms
コード長 1,189 bytes
コンパイル時間 2,461 ms
コンパイル使用メモリ 208,804 KB
実行使用メモリ 22,568 KB
最終ジャッジ日時 2024-04-23 20:46:00
合計ジャッジ時間 8,932 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 147 ms
13,184 KB
testcase_03 AC 231 ms
21,336 KB
testcase_04 AC 225 ms
21,208 KB
testcase_05 AC 190 ms
21,208 KB
testcase_06 AC 194 ms
21,204 KB
testcase_07 AC 68 ms
8,320 KB
testcase_08 AC 259 ms
21,888 KB
testcase_09 AC 24 ms
5,376 KB
testcase_10 AC 118 ms
11,776 KB
testcase_11 AC 81 ms
9,088 KB
testcase_12 AC 41 ms
7,296 KB
testcase_13 AC 143 ms
14,440 KB
testcase_14 AC 171 ms
16,896 KB
testcase_15 AC 201 ms
18,700 KB
testcase_16 AC 96 ms
11,428 KB
testcase_17 AC 217 ms
19,748 KB
testcase_18 AC 69 ms
9,216 KB
testcase_19 AC 206 ms
19,020 KB
testcase_20 AC 55 ms
7,808 KB
testcase_21 AC 83 ms
10,752 KB
testcase_22 AC 186 ms
17,796 KB
testcase_23 AC 4 ms
5,376 KB
testcase_24 AC 4 ms
5,376 KB
testcase_25 AC 37 ms
6,912 KB
testcase_26 AC 109 ms
12,580 KB
testcase_27 AC 111 ms
12,432 KB
testcase_28 AC 192 ms
18,108 KB
testcase_29 AC 24 ms
6,016 KB
testcase_30 AC 205 ms
19,780 KB
testcase_31 AC 140 ms
15,904 KB
testcase_32 AC 92 ms
11,320 KB
testcase_33 AC 197 ms
20,428 KB
testcase_34 AC 73 ms
9,472 KB
testcase_35 AC 210 ms
19,936 KB
testcase_36 AC 3 ms
5,376 KB
testcase_37 AC 5 ms
5,376 KB
testcase_38 AC 3 ms
5,376 KB
testcase_39 AC 4 ms
5,376 KB
testcase_40 AC 2 ms
5,376 KB
testcase_41 AC 327 ms
22,568 KB
testcase_42 AC 90 ms
9,216 KB
testcase_43 AC 160 ms
13,696 KB
testcase_44 AC 54 ms
7,040 KB
testcase_45 AC 154 ms
13,312 KB
testcase_46 AC 1 ms
5,376 KB
testcase_47 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 10000000000000000.0

double eps = 1e-7;

int main(){
	
	int N,M,X,Y;
	cin>>N>>M>>X>>Y;
	
	X--;Y--;
	
	vector<double> x(N),y(N);
	for(int i=0;i<N;i++)cin>>x[i]>>y[i];
	
	vector<vector<pair<int,double>>> E(N,vector<pair<int,double>>());
	
	for(int i=0;i<M;i++){
		int u,v;
		cin>>u>>v;
		u--;v--;
		double d = sqrt(pow(x[u]-x[v],2.0)+pow(y[u]-y[v],2.0));
		E[u].emplace_back(v,d);
		E[v].emplace_back(u,d);
	}
	
	vector<double> dis(N,Inf);
	vector<bool> visited(N,false);
	priority_queue<pair<double,int>,vector<pair<double,int>>,greater<pair<double,int>>> Q;
	Q.emplace(0.0,X);
	dis[X] = 0.0;
	
	while(Q.size()!=0){
		double D1 = Q.top().first;
		int from = Q.top().second;
		Q.pop();
		if(visited[from])continue;
		if(abs(dis[from]-D1)>eps)continue;
		visited[from]=true;
		for(int i=0;i<E[from].size();i++){
			int to = E[from][i].first;
			if(visited[to])continue;
			double D2 = E[from][i].second;
			if(dis[to]>D1+D2+eps){
				dis[to] = D1+D2;
				Q.emplace(dis[to],to);
			}
		}
	}
	
	cout<<fixed<<setprecision(10)<<dis[Y]<<endl;
	
	return 0;
}
0