結果
問題 | No.1065 電柱 / Pole (Easy) |
ユーザー |
![]() |
提出日時 | 2020-05-29 21:30:45 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 445 ms / 2,000 ms |
コード長 | 1,350 bytes |
コンパイル時間 | 2,378 ms |
コンパイル使用メモリ | 173,736 KB |
実行使用メモリ | 36,100 KB |
最終ジャッジ日時 | 2024-11-06 02:34:49 |
合計ジャッジ時間 | 10,361 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 46 |
ソースコード
#include "bits/stdc++.h" using namespace std; template<typename Type> vector<Type> Dijkstra(vector<vector<pair<long long, Type> > > Graph, long long Start) { using PT = pair<Type, long long>; const Type Inf = numeric_limits<Type>::max(); long long Size = Graph.size(); vector<Type> Dist; Dist.assign(Size, Inf); priority_queue<PT, vector<PT>, greater<PT> > PQ; Dist[Start] = 0; PQ.emplace(PT(Dist[Start], Start)); while (!PQ.empty()) { PT p = PQ.top(); PQ.pop(); Type D = p.first; long long E = p.second; if (Dist[E] < D) continue; for (pair<long long, Type> Next : Graph[E]) { Type ND = Next.second; long long NE = Next.first; if (Dist[NE] > Dist[E] + ND) { Dist[NE] = Dist[E] + ND; PQ.emplace(PT(Dist[NE], NE)); } } } return Dist; } int main() { int N, M, X, Y; cin >> N >> M >> X >> Y; X--, Y--; vector<pair<double, double> > P(N); vector<vector<pair<long long, double> > > V(N); for (int i = 0; i < N; i++) { cin >> P[i].first >> P[i].second; } for (int i = 0; i < M; i++) { int S, T; cin >> S >> T; S--, T--; double D = (P[S].first - P[T].first) * (P[S].first - P[T].first) + (P[S].second - P[T].second) * (P[S].second - P[T].second); D = sqrt(D); V[S].push_back({ T, D }); V[T].push_back({ S, D }); } vector<double> Dist = Dijkstra(V, X); printf("%.12lf\n", Dist[Y]); }