結果
| 問題 |
No.1065 電柱 / Pole (Easy)
|
| コンテスト | |
| ユーザー |
rniya
|
| 提出日時 | 2020-05-30 16:24:27 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 281 ms / 2,000 ms |
| コード長 | 1,426 bytes |
| コンパイル時間 | 2,087 ms |
| コンパイル使用メモリ | 179,024 KB |
| 実行使用メモリ | 24,064 KB |
| 最終ジャッジ日時 | 2024-11-07 19:21:50 |
| 合計ジャッジ時間 | 8,051 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 46 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
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){
fill(d.begin(),d.end(),inf);
d[s]=0;
priority_queue<P,vector<P>,greater<P>> pq;
pq.emplace(d[s],s);
while(!pq.empty()){
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[v]+c<d[u]){
d[u]=d[v]+c;
pq.emplace(d[u],u);
}
}
}
return d;
}
};
const int MAX_N=2e5+10;
int N,M,X,Y;
double p[MAX_N],q[MAX_N];
double dist(int i,int j){
return sqrt((p[i]-p[j])*(p[i]-p[j])+(q[i]-q[j])*(q[i]-q[j]));
}
int main(){
cin.tie(0);
ios::sync_with_stdio(false);
cin >> N >> M >> X >> Y;
for (int i=0;i<N;++i) cin >> p[i] >> q[i];
Dijkstra<double> D(N);
for (int i=0;i<M;++i){
int P,Q; cin >> P >> Q;
double d=dist(--P,--Q);
D.add_edge(P,Q,d);
D.add_edge(Q,P,d);
}
cout << fixed << setprecision(10);
cout << D.build(--X)[--Y] << '\n';
}
rniya