結果
問題 |
No.1065 電柱 / Pole (Easy)
|
ユーザー |
|
提出日時 | 2020-05-29 21:56:55 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 376 ms / 2,000 ms |
コード長 | 1,498 bytes |
コンパイル時間 | 1,895 ms |
コンパイル使用メモリ | 177,716 KB |
実行使用メモリ | 21,016 KB |
最終ジャッジ日時 | 2024-11-06 04:15:06 |
合計ジャッジ時間 | 9,308 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 46 |
ソースコード
#include <bits/stdc++.h> #define rep(i,n) for (int i = 0; i < (n); i ++) using namespace std; typedef long long ll; typedef pair<double,int> PL; typedef pair<int,int> P; const int INF = 1e9; const ll MOD = 1e12; const double eps = 1e-6; vector<double> dijkstra(int n, vector<vector<PL>>& G,int& s) { vector<double> dist(n,(double)INF); dist[s] = 0.0; priority_queue<PL,vector<PL>,greater<P>> q; q.push({0.0,s}); while (!q.empty()) { PL p = q.top(); q.pop(); double d = p.first; int v = p.second; if (dist[v] < d) continue; for (PL p: G[v]) { double cost = p.first; int e = p.second; if (dist[e] > dist[v] + cost) { dist[e] = dist[v] + cost; q.push({dist[e],e}); } } } return dist; } int main() { int N,M,X,Y; cin >> N >> M >> X >> Y; X--;Y--; vector<pair<int,int>> point(N); rep(i,N) cin >> point[i].first >> point[i].second; vector<vector<PL>> G(N); auto dist = [&](int x,int y){return sqrt((point[x].first - point[y].first) * (point[x].first - point[y].first) + (point[x].second - point[y].second) * (point[x].second - point[y].second));}; rep(_,M){ int p,q; cin >> p >> q; p --; q --; double d = dist(p,q); G[p].push_back(PL(d,q)); G[q].push_back(PL(d,p)); } vector<double> distance = dijkstra(N,G,X); double ans = distance[Y]; printf("%0.10f\n",ans); }