結果
問題 |
No.1065 電柱 / Pole (Easy)
|
ユーザー |
![]() |
提出日時 | 2020-09-17 10:54:49 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 196 ms / 2,000 ms |
コード長 | 2,538 bytes |
コンパイル時間 | 1,231 ms |
コンパイル使用メモリ | 127,212 KB |
最終ジャッジ日時 | 2025-01-14 15:36:34 |
ジャッジサーバーID (参考情報) |
judge1 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 46 |
ソースコード
#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; vector<edge> edges; int n; Graph(int n) :n(n) { g.resize(n); } void Add(int from, int to, T cost) { g[from].push_back({to, cost}); g[to].push_back({from, cost}); } void Add_Edge(int from, int to) { edges.push_back({from, to}); } }; template<typename T> vector<T> dijkstra(const 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 expected = pq.top().first; int i = pq.top().second; pq.pop(); if (dist[i] != expected) { continue; } for (auto e : g.g[i]) { int j = e.to; T c = e.cost; if (dist[j] > dist[i] + c) { dist[j] = dist[i] + c; pq.push({dist[j], j}); } } } return dist; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); 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> dist = dijkstra(G, x); cout << fixed << setprecision(17) << dist[y] << '\n'; return 0; }