結果
| 問題 |
No.1065 電柱 / Pole (Easy)
|
| コンテスト | |
| ユーザー |
trineutron
|
| 提出日時 | 2020-05-29 22:08:41 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 483 ms / 2,000 ms |
| コード長 | 1,127 bytes |
| コンパイル時間 | 4,131 ms |
| コンパイル使用メモリ | 207,208 KB |
| 最終ジャッジ日時 | 2025-01-10 17:27:00 |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 46 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m, x, y;
cin >> n >> m >> x >> y;
x--; y--;
vector<int> a(n), b(n);
for (int i = 0; i < n; i++) {
cin >> a.at(i) >> b.at(i);
}
vector<vector<pair<int, double>>> to(n);
for (int i = 0; i < m; i++) {
int p, q;
cin >> p >> q;
p--; q--;
int dx = a.at(p) - a.at(q), dy = b.at(p) - b.at(q);
to.at(p).emplace_back(q, sqrt(dx * dx + dy * dy));
to.at(q).emplace_back(p, sqrt(dx * dx + dy * dy));
}
vector<double> d(n, 1e9);
d.at(x) = 0;
priority_queue<pair<double, int>> que;
que.emplace(0, x);
while (!que.empty()) {
auto t = que.top();
double d0 = -t.first;
int v = t.second;
que.pop();
if (v == y) break;
if (d.at(v) < d0) continue;
for (auto next : to.at(v)) {
if (d.at(next.first) <= d0 + next.second) continue;
d.at(next.first) = d0 + next.second;
que.emplace(-d.at(next.first), next.first);
}
}
cout << setprecision(17) << d.at(y) << endl;
}
trineutron