結果
| 問題 |
No.1065 電柱 / Pole (Easy)
|
| コンテスト | |
| ユーザー |
SSRS
|
| 提出日時 | 2020-11-06 20:47:35 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 374 ms / 2,000 ms |
| コード長 | 963 bytes |
| コンパイル時間 | 1,864 ms |
| コンパイル使用メモリ | 177,484 KB |
| 実行使用メモリ | 22,980 KB |
| 最終ジャッジ日時 | 2024-07-22 11:56:43 |
| 合計ジャッジ時間 | 9,981 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 46 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
int main(){
cout << fixed << setprecision(5);
int N, M;
cin >> N >> M;
int X, Y;
cin >> X >> Y;
X--;
Y--;
vector<int> p(N), q(N);
for (int i = 0; i < N; i++){
cin >> p[i] >> q[i];
}
vector<vector<pair<double, int>>> E(N);
for (int i = 0; i < M; i++){
int P, Q;
cin >> P >> Q;
P--;
Q--;
double d = hypot(p[Q] - p[P], q[Q] - q[P]);
E[P].push_back(make_pair(d, Q));
E[Q].push_back(make_pair(d, P));
}
vector<double> d(N, -1);
priority_queue<pair<double, int>, vector<pair<double, int>>, greater<pair<double, int>>> pq;
pq.push(make_pair(0, X));
while (!pq.empty()){
double c = pq.top().first;
int v = pq.top().second;
pq.pop();
if (d[v] == -1){
d[v] = c;
for (auto P : E[v]){
int w = P.second;
if (d[w] == -1){
pq.push(make_pair(c + P.first, w));
}
}
}
}
cout << d[Y] << endl;
}
SSRS