結果
| 問題 |
No.1065 電柱 / Pole (Easy)
|
| コンテスト | |
| ユーザー |
realDivineJK
|
| 提出日時 | 2020-05-30 01:11:26 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 909 ms / 2,000 ms |
| コード長 | 1,571 bytes |
| コンパイル時間 | 2,154 ms |
| コンパイル使用メモリ | 187,056 KB |
| 実行使用メモリ | 32,580 KB |
| 最終ジャッジ日時 | 2024-11-06 13:17:13 |
| 合計ジャッジ時間 | 17,939 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 46 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
double calc_dist(int x1, int y1, int x2, int y2){
long long tmpx = (x1 - x2) * (x1 - x2);
long long tmpy = (y1 - y2) * (y1 - y2);
return sqrt(tmpx + tmpy);
}
int main(void){
// Your code here!
int N, M;
cin >> N >> M;
int X, Y;
cin >> X >> Y;
X--;
Y--;
map<int, vector<int>> D;
vector<pair<int, int>> p(N);
int x, y;
for (int i=0;i<N;i++){
cin >> x >> y;
p[i] = make_pair(x, y);
}
for (int i=0;i<M;i++){
cin >> x >> y;
x--;
y--;
if (D.count(x)){
D[x].push_back(y);
}
else{
D[x] = {y};
}
if (D.count(y)){
D[y].push_back(x);
}
else{
D[y] = {x};
}
}
priority_queue<pair<double, int>, vector<pair<double, int>>, greater<pair<double, int>>> pq;
vector<double> dist(N, 1e9);
dist[X] = 0.0;
for (int i=0;i<N;i++){
pq.push(make_pair(dist[i], i));
}
pair<double, int> tmp;
int r;
while (!pq.empty()){
tmp = pq.top();
pq.pop();
r = tmp.second;
if (D.count(r)){
for (int i: D[r]){
if (dist[i] > dist[r] + calc_dist(p[i].first, p[i].second, p[r].first, p[r].second)){
dist[i] = dist[r] + calc_dist(p[i].first, p[i].second, p[r].first, p[r].second);
pq.push(make_pair(dist[i], i));
}
}
}
}
printf("%.015f\n", dist[Y]);
return 0;
}
realDivineJK