結果
| 問題 |
No.1065 電柱 / Pole (Easy)
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-05-29 22:19:44 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 154 ms / 2,000 ms |
| コード長 | 1,944 bytes |
| コンパイル時間 | 2,082 ms |
| コンパイル使用メモリ | 206,588 KB |
| 最終ジャッジ日時 | 2025-01-10 17:41:13 |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 46 |
ソースコード
#include <bits/stdc++.h> // clang-format off
using Int = long long;
#define REP_(i, a_, b_, a, b, ...) for (Int i = (a), lim##i = (b); i < lim##i; i++)
#define REP(i, ...) REP_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
struct SetupIO { SetupIO() { std::cin.tie(nullptr), std::ios::sync_with_stdio(false), std::cout << std::fixed << std::setprecision(13); } } setup_io;
#ifndef dump
#define dump(...)
#endif // clang-format on
/**
* author: knshnb
* created: Fri May 29 22:12:23 JST 2020
**/
template <class T, bool directed = true> struct Dijkstra {
struct Edge {
int to;
T cost;
};
std::vector<std::vector<Edge>> g;
Dijkstra(int n) : g(n) {}
void add_edge(int u, int v, T cost) {
g[u].push_back({v, cost});
if (!directed) g[v].push_back({u, cost});
}
std::vector<T> run(int s) {
std::vector<T> dist(g.size(), std::numeric_limits<T>::max() / 2);
// {d, v}
std::priority_queue<std::pair<T, int>, std::vector<std::pair<T, int>>, std::greater<std::pair<T, int>>> q;
q.push({0, s});
while (!q.empty()) {
std::pair<T, int> p = q.top();
q.pop();
int v = p.second;
if (dist[v] <= p.first) continue;
dist[v] = p.first;
for (const Edge& e : g[v]) {
if (dist[e.to] <= p.first + e.cost) continue; // 定数倍枝刈り
q.emplace(p.first + e.cost, e.to);
}
}
return dist;
}
};
signed main() {
Int n, m, x, y;
std::cin >> n >> m >> x >> y;
x--, y--;
Dijkstra<double, false> g(n);
std::vector<Int> p(n), q(n);
REP(i, n) std::cin >> p[i] >> q[i];
REP(i, m) {
Int u, v;
std::cin >> u >> v;
u--, v--;
double dx = p[u] - p[v], dy = q[u] - q[v];
g.add_edge(u, v, sqrt(dx * dx + dy * dy));
}
std::cout << g.run(x)[y] << std::endl;
}