結果

問題 No.1065 電柱 / Pole (Easy)
ユーザー m-44m-44
提出日時 2020-05-29 21:50:50
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 290 ms / 2,000 ms
コード長 930 bytes
コンパイル時間 1,633 ms
コンパイル使用メモリ 169,880 KB
実行使用メモリ 21,880 KB
最終ジャッジ日時 2024-04-23 21:29:40
合計ジャッジ時間 8,369 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 126 ms
12,572 KB
testcase_03 AC 204 ms
21,880 KB
testcase_04 AC 203 ms
20,964 KB
testcase_05 AC 169 ms
21,316 KB
testcase_06 AC 182 ms
20,220 KB
testcase_07 AC 57 ms
8,192 KB
testcase_08 AC 215 ms
20,664 KB
testcase_09 AC 20 ms
6,940 KB
testcase_10 AC 96 ms
11,264 KB
testcase_11 AC 65 ms
8,960 KB
testcase_12 AC 42 ms
7,168 KB
testcase_13 AC 134 ms
13,976 KB
testcase_14 AC 161 ms
15,924 KB
testcase_15 AC 183 ms
17,508 KB
testcase_16 AC 92 ms
11,040 KB
testcase_17 AC 219 ms
18,632 KB
testcase_18 AC 73 ms
8,876 KB
testcase_19 AC 191 ms
17,872 KB
testcase_20 AC 56 ms
7,424 KB
testcase_21 AC 89 ms
10,412 KB
testcase_22 AC 173 ms
16,692 KB
testcase_23 AC 4 ms
6,944 KB
testcase_24 AC 4 ms
6,940 KB
testcase_25 AC 39 ms
6,944 KB
testcase_26 AC 105 ms
11,808 KB
testcase_27 AC 103 ms
11,872 KB
testcase_28 AC 176 ms
17,276 KB
testcase_29 AC 23 ms
6,944 KB
testcase_30 AC 179 ms
18,544 KB
testcase_31 AC 128 ms
15,040 KB
testcase_32 AC 81 ms
10,720 KB
testcase_33 AC 174 ms
19,976 KB
testcase_34 AC 67 ms
9,108 KB
testcase_35 AC 187 ms
18,884 KB
testcase_36 AC 3 ms
6,940 KB
testcase_37 AC 4 ms
6,944 KB
testcase_38 AC 3 ms
6,940 KB
testcase_39 AC 3 ms
6,940 KB
testcase_40 AC 2 ms
6,944 KB
testcase_41 AC 290 ms
21,256 KB
testcase_42 AC 81 ms
9,344 KB
testcase_43 AC 132 ms
13,056 KB
testcase_44 AC 48 ms
7,296 KB
testcase_45 AC 137 ms
12,800 KB
testcase_46 AC 2 ms
6,944 KB
testcase_47 AC 1 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

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