結果
| 問題 |
No.1065 電柱 / Pole (Easy)
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-06-20 10:41:00 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 232 ms / 2,000 ms |
| コード長 | 1,603 bytes |
| コンパイル時間 | 1,273 ms |
| コンパイル使用メモリ | 111,604 KB |
| 最終ジャッジ日時 | 2025-01-11 08:33:56 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 46 |
ソースコード
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <math.h>
#include <deque>
#include <queue>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
template<typename T>
struct Dijkstra{
const T inf=numeric_limits<T>::max();
using P=pair<T,int>;
int n;
vector<vector<pair<int,T>>> g;
vector<T> d;
Dijkstra(int n):n(n),g(n),d(n){}
void add_edge(int u,int v,T w){
g[u].emplace_back(v,w);
}
vector<T> build(int s){
for(int i=0;i<n;i++){
d[i]=inf;
}
d[s]=0;
priority_queue<P,vector<P>,greater<P>> pq;
pq.emplace(d[s],s);
while(pq.size()){
P p=pq.top(); pq.pop();
int v=p.second;
if(d[v]<p.first)continue;
for(auto &e:g[v]){
int u=e.first; T c=e.second;
if(d[u]>d[v]+c){
d[u]=d[v]+c;
pq.emplace(d[u],u);
}
}
}
return d;
}
};
double dist(int x,int y,int xx,int yy){
return sqrt((x-xx)*(x-xx)+(y-yy)*(y-yy));
}
int main(){
cin.tie(nullptr);
ios::sync_with_stdio(false);
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];
}
Dijkstra<double> D(n);
while(m--){
int a,b; cin >> a >> b;
a--; b--;
double d=dist(p[a],q[a],p[b],q[b]);
D.add_edge(a,b,d);
D.add_edge(b,a,d);
}
printf("%.9f\n",D.build(x)[y]);
}