結果
| 問題 |
No.1065 電柱 / Pole (Easy)
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-05-30 10:07:59 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 407 ms / 2,000 ms |
| コード長 | 1,195 bytes |
| コンパイル時間 | 1,212 ms |
| コンパイル使用メモリ | 111,140 KB |
| 最終ジャッジ日時 | 2025-01-10 19:14:15 |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 46 |
ソースコード
#include <iostream>
#include <vector>
#include <climits>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <bitset>
#include <utility>
#include <numeric>
#include <queue>
#include <stack>
using ll = long long;
using namespace std;
constexpr int MOD = 1e9 + 7;
constexpr ll MOD_LL = ll(1e9) + 7;
int main(void) {
int n, m, x, y;
cin >> n >> m >> x >> y;
x--; y--;
vector<int> p(n), q(n);
for(int i = 0; i < n; ++i) {
cin >> p[i] >> q[i];
}
vector< vector<int> > G(n);
for(int i = 0; i < m; ++i) {
int a, b;
cin >> a >> b;
a--; b--;
G[a].push_back(b);
G[b].push_back(a);
}
vector<double> dist(n, 1e9 + 10);
dist[x] = 0.0;
priority_queue< pair<double, int> > que;
que.push( {0.0, x} );
while( !que.empty() ) {
double now_cost = -que.top().first;
int now = que.top().second;
que.pop();
if( dist[now] != now_cost ) continue;
for(auto &to : G[now]) {
double cost = now_cost + sqrt((p[now] - p[to]) * (p[now] - p[to]) + (q[now] - q[to]) * (q[now] - q[to]));
if( dist[to] > cost ) {
dist[to] = cost;
que.push( {-cost, to} );
}
}
}
printf("%.12f\n", dist[y]);
return 0;
}