結果

問題 No.1065 電柱 / Pole (Easy)
ユーザー furafura
提出日時 2020-05-30 00:02:11
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 163 ms / 2,000 ms
コード長 1,135 bytes
コンパイル時間 2,345 ms
コンパイル使用メモリ 206,188 KB
実行使用メモリ 20,864 KB
最終ジャッジ日時 2024-04-24 02:41:34
合計ジャッジ時間 6,682 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 75 ms
12,416 KB
testcase_03 AC 110 ms
20,268 KB
testcase_04 AC 107 ms
20,164 KB
testcase_05 AC 88 ms
20,168 KB
testcase_06 AC 86 ms
20,036 KB
testcase_07 AC 26 ms
7,936 KB
testcase_08 AC 97 ms
20,224 KB
testcase_09 AC 10 ms
5,376 KB
testcase_10 AC 43 ms
11,008 KB
testcase_11 AC 31 ms
8,704 KB
testcase_12 AC 21 ms
7,168 KB
testcase_13 AC 79 ms
13,888 KB
testcase_14 AC 90 ms
16,008 KB
testcase_15 AC 102 ms
17,776 KB
testcase_16 AC 54 ms
11,320 KB
testcase_17 AC 115 ms
18,772 KB
testcase_18 AC 38 ms
8,960 KB
testcase_19 AC 106 ms
18,008 KB
testcase_20 AC 28 ms
7,552 KB
testcase_21 AC 47 ms
10,368 KB
testcase_22 AC 107 ms
16,960 KB
testcase_23 AC 3 ms
5,376 KB
testcase_24 AC 3 ms
5,376 KB
testcase_25 AC 21 ms
6,912 KB
testcase_26 AC 56 ms
11,932 KB
testcase_27 AC 58 ms
12,008 KB
testcase_28 AC 101 ms
17,416 KB
testcase_29 AC 14 ms
6,144 KB
testcase_30 AC 105 ms
18,688 KB
testcase_31 AC 72 ms
15,184 KB
testcase_32 AC 46 ms
10,736 KB
testcase_33 AC 104 ms
19,472 KB
testcase_34 AC 41 ms
9,088 KB
testcase_35 AC 114 ms
19,016 KB
testcase_36 AC 3 ms
5,376 KB
testcase_37 AC 3 ms
5,376 KB
testcase_38 AC 3 ms
5,376 KB
testcase_39 AC 3 ms
5,376 KB
testcase_40 AC 2 ms
5,376 KB
testcase_41 AC 163 ms
20,864 KB
testcase_42 AC 41 ms
8,832 KB
testcase_43 AC 74 ms
12,800 KB
testcase_44 AC 26 ms
7,040 KB
testcase_45 AC 72 ms
12,544 KB
testcase_46 AC 2 ms
5,376 KB
testcase_47 AC 1 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

template<class T> struct edge{
	int to;
	T wt;
	edge(int to,const T& wt):to(to),wt(wt){}
};
template<class T> using weighted_graph=vector<vector<edge<T>>>;

template<class T>
void add_edge(weighted_graph<T>& G,int u,int v,const T& wt){
	G[u].emplace_back(v,wt);
	G[v].emplace_back(u,wt);
}

template<class T>
vector<T> Dijkstra(const weighted_graph<T>& G,int s){
	const T INF=numeric_limits<T>::max();
	int n=G.size();
	vector<T> d(n,INF); d[s]=0;
	priority_queue<pair<T,int>> Q; Q.emplace(0,s);
	while(!Q.empty()){
		T d0=-Q.top().first;
		int u=Q.top().second; Q.pop();
		if(d0>d[u]) continue;
		for(const auto& e:G[u]){
			int v=e.to;
			if(d[v]>d[u]+e.wt) d[v]=d[u]+e.wt, Q.emplace(-d[v],v);
		}
	}
	return d;
}

int main(){
	int n,m; scanf("%d%d",&n,&m);
	int s,t; scanf("%d%d",&s,&t); s--; t--;
	vector<int> x(n),y(n);
	rep(i,n) scanf("%d%d",&x[i],&y[i]);

	weighted_graph<double> G(n);
	rep(i,m){
		int u,v; scanf("%d%d",&u,&v); u--; v--;
		add_edge(G,u,v,hypot(x[u]-x[v],y[u]-y[v]));
	}

	printf("%.9f\n",Dijkstra(G,s)[t]);

	return 0;
}
0