結果
| 問題 | No.1065 電柱 / Pole (Easy) |
| コンテスト | |
| ユーザー |
realDivineJK
|
| 提出日時 | 2020-05-30 00:50:44 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.89.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,624 bytes |
| 記録 | |
| コンパイル時間 | 2,136 ms |
| コンパイル使用メモリ | 192,692 KB |
| 実行使用メモリ | 78,832 KB |
| 最終ジャッジ日時 | 2024-11-06 12:20:17 |
| 合計ジャッジ時間 | 34,911 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 21 WA * 25 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
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;
map<long long, double> distD;
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};
}
distD[x*N+y] = sqrt((p[x].first-p[y].first)*(p[x].first-p[y].first)+(p[x].second-p[y].second)*(p[x].second-p[y].second));
distD[y*N+x] = sqrt((p[x].first-p[y].first)*(p[x].first-p[y].first)+(p[x].second-p[y].second)*(p[x].second-p[y].second));
}
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] + distD[(long long)r*N+i]){
dist[i] = dist[r] + distD[(long long)r*N+i];
pq.push(make_pair(dist[i], i));
}
}
}
}
printf("%.015f\n", dist[Y]);
return 0;
}
realDivineJK