結果
問題 | No.1065 電柱 / Pole (Easy) |
ユーザー |
![]() |
提出日時 | 2020-05-29 21:45:10 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 358 ms / 2,000 ms |
コード長 | 2,429 bytes |
コンパイル時間 | 1,001 ms |
コンパイル使用メモリ | 90,856 KB |
実行使用メモリ | 25,384 KB |
最終ジャッジ日時 | 2024-11-06 03:26:54 |
合計ジャッジ時間 | 8,824 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 46 |
ソースコード
#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; }