結果

問題 No.1065 電柱 / Pole (Easy)
ユーザー queee
提出日時 2020-05-29 23:07:31
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 362 ms / 2,000 ms
コード長 1,667 bytes
コンパイル時間 887 ms
コンパイル使用メモリ 93,136 KB
実行使用メモリ 18,988 KB
最終ジャッジ日時 2024-11-06 07:31:09
合計ジャッジ時間 8,720 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 46
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <cmath>
#include <functional>
#define DB puts("D")
#define pb push_back

using namespace std; using ll=long long; using ld=long double; const int INF=1e9; const ll LINF=1e18; const double dINF = 1e18; const ld ldINF = 1e18; const double EPS = 1e-6;
template<typename T, typename U, typename O> void caut(T a, U b, O c){cout<<"("<<a<<","<<b<<","<<c<<") ";}
template<typename T, typename U> void caut(T a, U b){cout<<"("<<a<<","<<b<<") ";}
template<typename T> void caut(T a){cout<<"("<<a<<") ";}
template<typename T> void input(T a[], int n){for(int i=0;i<n;i++) cin>>a[i];}
template<typename T, typename U> void input(T a[], U b[], int n){for(int i=0;i<n;i++) cin>>a[i]>>b[i];}
template<typename T, typename U, typename O> void input(T a[], U b[], O[], int n){for(int i=0;i<n;i++) cin>>a[i]>>b[i];}

using P=pair<double,int>;

int main() {
  int n,m; cin>>n>>m;
  int x,y; cin>>x>>y; x--; y--;
  double p[n],q[n]; input(p,q,n);
  vector<int> v[n];
  for(int i=0;i<m;i++) {
    int a,b; cin>>a>>b;; a--;b--;
    v[a].push_back(b); v[b].push_back(a);
  }
  
  priority_queue<P, vector<P>, greater<P>> que; que.push({0,x});
  double an[n]; fill(an,an+n,dINF); an[x]=0;
  while(!que.empty()) {
    P top = que.top(); que.pop();
    int f = top.second;
    if (top.first - EPS > an[top.second]) continue;
    for(int x : v[f]) {
      double dis = sqrt((p[x]-p[f])*(p[x]-p[f])+(q[x]-q[f])*(q[x]-q[f]));
      if (an[x] > an[f] + dis) {
        an[x] = an[f] + dis;
        que.push({an[x], x});
      }
    }
  }
  cout.precision(10);
  cout<<an[y]<<endl;
}
0