結果
問題 | No.1065 電柱 / Pole (Easy) |
ユーザー |
![]() |
提出日時 | 2020-05-29 21:52:53 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 420 ms / 2,000 ms |
コード長 | 1,934 bytes |
コンパイル時間 | 2,725 ms |
コンパイル使用メモリ | 207,160 KB |
最終ジャッジ日時 | 2025-01-10 17:02:27 |
ジャッジサーバーID (参考情報) |
judge3 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 46 |
ソースコード
#include <bits/stdc++.h> using namespace std; 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; cin >> n >> m; int x, y; cin >> x >> y; --x; --y; vector<int> p(n), q(n); for (int i = 0; i < n; ++i) { cin >> p[i] >> q[i]; } Graph<double> g(n); for (int i = 0; i < m; ++i) { int u, v; cin >> u >> v; --u; --v; double dist = sqrt((p[u] - p[v]) * (p[u] - p[v]) + (q[u] - q[v]) * (q[u] - q[v])); g.Add(u, v, dist); g.Add(v, u, dist); } vector<double> dist = dijkstra(g, x); cout << fixed << setprecision(17) << dist[y] << '\n'; return 0; }