結果

問題 No.1065 電柱 / Pole (Easy)
ユーザー leaf_1415leaf_1415
提出日時 2020-05-29 21:45:10
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 424 ms / 2,000 ms
コード長 2,429 bytes
コンパイル時間 1,133 ms
コンパイル使用メモリ 89,820 KB
実行使用メモリ 24,936 KB
最終ジャッジ日時 2024-04-23 21:07:35
合計ジャッジ時間 9,405 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
10,736 KB
testcase_01 AC 5 ms
11,504 KB
testcase_02 AC 202 ms
18,080 KB
testcase_03 AC 268 ms
24,720 KB
testcase_04 AC 268 ms
24,936 KB
testcase_05 AC 216 ms
24,704 KB
testcase_06 AC 218 ms
23,768 KB
testcase_07 AC 77 ms
13,504 KB
testcase_08 AC 288 ms
22,092 KB
testcase_09 AC 28 ms
11,628 KB
testcase_10 AC 130 ms
16,208 KB
testcase_11 AC 91 ms
14,676 KB
testcase_12 AC 53 ms
15,540 KB
testcase_13 AC 194 ms
19,512 KB
testcase_14 AC 225 ms
21,276 KB
testcase_15 AC 261 ms
21,828 KB
testcase_16 AC 125 ms
17,944 KB
testcase_17 AC 285 ms
23,328 KB
testcase_18 AC 89 ms
16,084 KB
testcase_19 AC 272 ms
21,860 KB
testcase_20 AC 73 ms
14,272 KB
testcase_21 AC 107 ms
17,128 KB
testcase_22 AC 243 ms
21,596 KB
testcase_23 AC 6 ms
11,096 KB
testcase_24 AC 7 ms
11,224 KB
testcase_25 AC 48 ms
14,228 KB
testcase_26 AC 142 ms
17,720 KB
testcase_27 AC 145 ms
18,144 KB
testcase_28 AC 251 ms
22,488 KB
testcase_29 AC 31 ms
11,080 KB
testcase_30 AC 263 ms
22,872 KB
testcase_31 AC 187 ms
20,664 KB
testcase_32 AC 122 ms
16,712 KB
testcase_33 AC 262 ms
23,784 KB
testcase_34 AC 94 ms
16,476 KB
testcase_35 AC 263 ms
23,188 KB
testcase_36 AC 5 ms
9,152 KB
testcase_37 AC 7 ms
11,668 KB
testcase_38 AC 6 ms
10,908 KB
testcase_39 AC 7 ms
9,544 KB
testcase_40 AC 5 ms
9,540 KB
testcase_41 AC 424 ms
22,848 KB
testcase_42 AC 120 ms
14,120 KB
testcase_43 AC 212 ms
17,932 KB
testcase_44 AC 71 ms
12,924 KB
testcase_45 AC 205 ms
18,120 KB
testcase_46 AC 4 ms
9,408 KB
testcase_47 AC 4 ms
9,024 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <cassert>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <string>
#include <algorithm>
#include <utility>
#define llint long long
#define inf 1e18
#define rep(x, s, t) for(llint (x) = (s); (x) < (t); (x)++)
#define Rep(x, s, t) for(llint (x) = (s); (x) <= (t); (x)++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))
#define eps 1e-9

using namespace std;
typedef pair<double, llint> P;

struct edge{
	llint to;
	double cost;
	edge(){}
	edge(llint a, double b){
		to = a, cost = b;
	}
};

struct vec2d{
	double x, y;
	vec2d(){}
	vec2d(double x, double y){
		this->x = x, this->y = y;
	}
	double add(double a, double b){
		if(fabs(a+b) < eps * (fabs(a) + fabs(b))) return 0.0;
		return a+b;
	}
	vec2d operator+(vec2d ope){
		return vec2d(add(x, ope.x), add(y, ope.y));
	}
	vec2d operator-(vec2d ope){
		return vec2d(add(x, -ope.x), add(y, -ope.y));
	}
	vec2d operator*(double t){
		return vec2d(x*t, y*t);
	}
	vec2d operator/(double t){
		return vec2d(x/t, y/t);
	}
	double dot(vec2d ope){
		return add(x*ope.x, y*ope.y);
	}
	double cross(vec2d ope){
		return add(x*ope.y, -y*ope.x);
	}
	double norm(){
		double d2 = dot(*this);
		if(d2 > 0) return sqrt(d2);
		return 0.0;
	}
};

double distPP(vec2d p, vec2d q){
	return (p-q).norm();
}


llint n, m, s, t;
vector<edge> G[200005];
vec2d p[200005];
double dist[200005];

void dijkstra(vector<edge> G[], llint S, double dist[])
{
	for(int i = 0; i <= n; i++) dist[i] = inf;
	dist[S] = 0;
	
	priority_queue< P, vector<P>, greater<P> > Q;
	Q.push( make_pair(0, S) );
	
	llint v; double d;
	while(Q.size()){
		d = Q.top().first;
		v = Q.top().second;
		Q.pop();
		if(dist[v] < d) continue;
		for(int i = 0; i < G[v].size(); i++){
			if(dist[G[v][i].to] > d + G[v][i].cost){
				dist[G[v][i].to] = d + G[v][i].cost;
				Q.push( make_pair(dist[G[v][i].to], G[v][i].to) );
			}
		}
	}
}

int main(void)
{
	//ios::sync_with_stdio(0);
	//cin.tie(0);
	
	cin >> n >> m >> s >> t;
	for(int i = 1; i <= n; i++){
		cin >> p[i].x >> p[i].y;
	}
	llint u, v;
	for(int i = 1; i <= m; i++){
		cin >> u >> v;
		double w = distPP(p[u], p[v]);
		G[u].push_back(edge(v, w));
		G[v].push_back(edge(u, w));
	}
	
	dijkstra(G, s, dist);
	
	printf("%.11f\n", dist[t]);
	
	return 0;
}
0