結果
| 問題 |
No.1065 電柱 / Pole (Easy)
|
| コンテスト | |
| ユーザー |
iqueue02
|
| 提出日時 | 2020-05-30 23:28:14 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 426 ms / 2,000 ms |
| コード長 | 1,229 bytes |
| コンパイル時間 | 2,008 ms |
| コンパイル使用メモリ | 209,380 KB |
| 最終ジャッジ日時 | 2025-01-10 19:43:19 |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 46 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n);i++)
#define sz(x) int(x.size())
typedef long long ll;
typedef pair<int,int> P;
constexpr int INF = 2e9;
typedef long double ld;
int main() {
int n, m;
cin >> n >> m;
int x, y;
cin >> x >> y;
x--; y--;
vector<pair<ld, ld>> p;
rep(i,n) {
ld a, b;
cin >> a >> b;
p.emplace_back(make_pair(a, b));
}
vector<vector<pair<int, ld>>> g(n);
rep(i,m) {
int u, v;
cin >> u >> v;
u--; v--;
ld s = (p[u].first - p[v].first), t = (p[u].second - p[v].second);
ld d = sqrt((s * s) + (t * t));
g[u].emplace_back(make_pair(v, d));
g[v].emplace_back(make_pair(u, d));
}
vector<ld> dist(n, INF);
priority_queue<pair<ld, int>, vector<pair<ld, int>>, greater<pair<ld, int>>> pq;
pq.push(make_pair(0.0, x));
dist[x] = 0.0;
while (!pq.empty()) {
auto t = pq.top();
pq.pop();
int u = t.second;
if (t.first > dist[u]) continue;
for (auto e : g[u]) {
ld cost = e.second;
int v = e.first;
if (dist[v] > dist[u] + cost) {
dist[v] = dist[u] + cost;
pq.push(make_pair(dist[v], v));
}
}
}
printf("%.12Lf\n", dist[y]);
return 0;
}
iqueue02