結果
| 問題 |
No.1065 電柱 / Pole (Easy)
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-05-29 21:40:41 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 398 ms / 2,000 ms |
| コード長 | 1,558 bytes |
| コンパイル時間 | 2,011 ms |
| コンパイル使用メモリ | 179,680 KB |
| 実行使用メモリ | 27,100 KB |
| 最終ジャッジ日時 | 2024-11-06 03:01:00 |
| 合計ジャッジ時間 | 10,182 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 46 |
ソースコード
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
using ll = long long ;
using P = pair<int,int> ;
using pll = pair<double,long long>;
constexpr int INF = 1e9;
constexpr long long LINF = 1e17;
constexpr int MOD = 1000000007;
int n = 200005;
int m;
vector<vector<pll>> graph(n,vector<pll>());
vector<double> Dijkstra(int start){
vector<bool> seen(n,false);
vector<double> shortest(n,LINF);
priority_queue<pll,vector<pll>,greater<pll>> pq;
pq.push(pll(0.0,start));
while(!pq.empty()){
double dist = pq.top().first;
int node = pq.top().second;
pq.pop();
if(seen[node]) continue;
shortest[node] = dist;
seen[node] = true;
for(pll next:graph[node]){
int next_node = next.second;
double next_cost = next.first;
if(seen[next_node]) continue;
pq.push(pll(next_cost + dist,next_node));
}
}
return shortest;
}
int main(){
cin >> n >> m;
int x,y;
cin >> x >> y;
--x;--y;
vector<pair<double,double>> pq(n);
rep(i,n) cin >> pq[i].first >> pq[i].second;
rep(i,m){
int p,q;
cin >> p >> q;
--p;--q;
double dis = sqrt((pq[p].first - pq[q].first)*(pq[p].first - pq[q].first) + (pq[p].second-pq[q].second)*(pq[p].second-pq[q].second));
graph[p].push_back(pll(dis,q));
graph[q].push_back(pll(dis,p));
}
vector<double> ans = Dijkstra(x);
cout << setprecision(20) << ans[y] << endl;
return 0;
}