結果

問題 No.1065 電柱 / Pole (Easy)
ユーザー Jiro_tech15
提出日時 2020-05-29 21:36:56
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 380 ms / 2,000 ms
コード長 1,641 bytes
コンパイル時間 1,170 ms
コンパイル使用メモリ 107,128 KB
実行使用メモリ 23,984 KB
最終ジャッジ日時 2024-11-06 02:49:23
合計ジャッジ時間 9,083 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 46
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define INF (int)(1123456789)
#define LINF (long long int)(112345678901234567)
#define MAX_V 200005
//lower_bound使え

struct edge{int to; double cost;};
typedef pair<double, int> P;//最短距離、頂点番号

int V;
vector<edge> G[MAX_V];
double d[MAX_V];

void dijkstra(int s){
  priority_queue<P, vector<P>, greater<P> > que;
  fill(d,d+V,LINF);
  d[s] = 0;
  que.push(P(0,s));

  while(!que.empty()){
    P p = que.top(); que.pop();
    int v = p.second;
    if(d[v] < p.first) continue;
    rep(i, G[v].size()){
      edge e = G[v][i];
      if(d[e.to] > d[v] + e.cost){
        d[e.to] = d[v] + e.cost;
        que.push(P(d[e.to], e.to));
      }
    }
  }
}

/*
 * 頂点数をVに代入すること
 */
int main(void){
  cout<<fixed<<setprecision(15);
  int n,m;cin>>n>>m;
  V=n;
  int s,t;cin>>s>>t;s--;t--;

  vector<ll> X,Y;
  rep(i,n){
    int p,q;cin>>p>>q;
    X.push_back(p);
    Y.push_back(q);
  }
  rep(i,m){
    int p,q;cin>>p>>q;
    p--;q--;
    double dist = sqrt((X[p]-X[q]) * (X[p]-X[q]) + (Y[p]-Y[q]) * (Y[p]-Y[q]));
    G[p].push_back({q,dist});
    G[q].push_back({p,dist});
  }

  dijkstra(s);
  cout << d[t] << endl;
  return 0;
}
0