結果

問題 No.1065 電柱 / Pole (Easy)
ユーザー m-44
提出日時 2020-05-29 21:50:50
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 355 ms / 2,000 ms
コード長 930 bytes
コンパイル時間 1,929 ms
コンパイル使用メモリ 173,960 KB
実行使用メモリ 21,072 KB
最終ジャッジ日時 2024-11-06 03:49:46
合計ジャッジ時間 8,918 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 46
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

typedef pair<double, int> pdi;
int main() {
  int N, M, X, Y;
  cin>>N>>M>>X>>Y;
  --X;
  --Y;
  int p[N], q[N];
  for (int i=0; i<N; i++) {
    cin>>p[i]>>q[i];
  }
  vector<pdi> g[N];
  for (int i=0; i<M; i++) {
    int P, Q;
    cin>>P>>Q;
    --P;
    --Q;
    double dist = sqrt(pow(p[P] - p[Q], 2) + pow(q[P] - q[Q], 2));
    g[P].push_back(make_pair(dist, Q));
    g[Q].push_back(make_pair(dist, P));
  }
  priority_queue<pdi, vector<pdi>, greater<pdi>> pq;
  pq.push(make_pair(0.0, X));
  double ans[N];
  for (int i=0; i<N; i++) ans[i] = 1e12;
  while (!pq.empty()) {
    auto top = pq.top();
    pq.pop();
    double cost = top.first;
    int cur = top.second;
    for (auto e: g[cur]) {
      if (ans[e.second] > cost + e.first) {
        ans[e.second] = cost + e.first;
        pq.push(make_pair(ans[e.second], e.second));
      }
    }
  }
  printf("%.9lf\n", ans[Y]);
}
0