結果
問題 | No.1065 電柱 / Pole (Easy) |
ユーザー |
![]() |
提出日時 | 2020-09-17 10:58:03 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
RE
(最新)
AC
(最初)
|
実行時間 | - |
コード長 | 2,325 bytes |
コンパイル時間 | 1,706 ms |
コンパイル使用メモリ | 129,640 KB |
最終ジャッジ日時 | 2025-01-14 15:37:35 |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | RE * 2 |
other | RE * 42 MLE * 4 |
ソースコード
#include <iostream> #include <string> #include <vector> #include <algorithm> #include <utility> #include <tuple> #include <cstdint> #include <cstdio> #include <map> #include <queue> #include <set> #include <stack> #include <deque> #include <unordered_map> #include <unordered_set> #include <bitset> #include <cctype> #include <numeric> #include <cmath> #include <iomanip> //cout << fixed << setprecision(15) << << endl; #include <cassert> #include <limits> //#include "atcoder/all" using namespace std; //using namespace atcoder; #define ll long long int #define pb push_back #define rep(i,n) for(int i=0;i<(n);i++) #define REP(i,n) for(int i=1;i<=(n);i++) //#define P pair<int,int> int mx8[] = {0,0,1,-1,-1,1,-1,1}; int my8[] = {-1,1,0,0,-1,-1,1,1}; int mx4[] = {1,-1,0,0}; int my4[] = {0,0,-1,1}; template<typename T> class Graph { public: struct Edge { int to; T cost; }; struct edge { int from; int to; }; vector<vector<Edge>> g; int n; Graph(int n) { g.resize(n); } void Add(int from, int to, T cost) { g[from].push_back({to,cost}); g[to].push_back({from,cost}); } }; template<typename T> vector<T> dijkstra(Graph<T> G, int start) { using P = pair<T,int>; vector<T> dist(G.n, numeric_limits<T>::max()); priority_queue<P,vector<P>,greater<P>> pq; dist[start] = 0; pq.push({dist[start],start}); while(!pq.empty()) { T COST = pq.top().first; int v = pq.top().second; pq.pop(); if(dist[v] < COST) { continue; } for(auto e : G.g[v]) { int j = e.to; T c = e.cost; if(dist[j] > dist[v] + c) { dist[j] = dist[v] + c; pq.push({dist[j],j}); } } } return dist; } int main(){ int n, m, x, y; cin >> n >> m >> x >> y; --x; --y; vector<double> p(n),q(n); rep(i,n) cin >> p[i] >> q[i]; Graph<double> G(n); rep(i,m){ int P, Q; cin >> P >> Q; P--; Q--; double Co = sqrt(pow((p[P]-p[Q]),2) + pow((q[P]-q[Q]),2)); G.Add(P,Q,Co); } vector<double> ans; ans = dijkstra(G,x); cout << fixed << setprecision(17) << ans[y] << endl; }