結果

問題 No.1065 電柱 / Pole (Easy)
ユーザー kk
提出日時 2020-10-14 22:18:58
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 171 ms / 2,000 ms
コード長 1,165 bytes
コンパイル時間 4,233 ms
コンパイル使用メモリ 209,540 KB
実行使用メモリ 23,016 KB
最終ジャッジ日時 2023-09-28 00:59:14
合計ジャッジ時間 11,452 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
9,796 KB
testcase_01 AC 4 ms
9,944 KB
testcase_02 AC 74 ms
15,436 KB
testcase_03 AC 105 ms
22,296 KB
testcase_04 AC 105 ms
22,140 KB
testcase_05 AC 79 ms
22,124 KB
testcase_06 AC 82 ms
22,680 KB
testcase_07 AC 28 ms
12,364 KB
testcase_08 AC 94 ms
20,184 KB
testcase_09 AC 12 ms
10,896 KB
testcase_10 AC 46 ms
14,136 KB
testcase_11 AC 30 ms
12,736 KB
testcase_12 AC 25 ms
13,384 KB
testcase_13 AC 80 ms
17,492 KB
testcase_14 AC 94 ms
18,828 KB
testcase_15 AC 113 ms
19,844 KB
testcase_16 AC 57 ms
16,008 KB
testcase_17 AC 126 ms
20,848 KB
testcase_18 AC 41 ms
14,308 KB
testcase_19 AC 119 ms
19,984 KB
testcase_20 AC 31 ms
12,512 KB
testcase_21 AC 48 ms
15,992 KB
testcase_22 AC 101 ms
19,460 KB
testcase_23 AC 5 ms
10,024 KB
testcase_24 AC 5 ms
10,048 KB
testcase_25 AC 21 ms
13,224 KB
testcase_26 AC 58 ms
15,896 KB
testcase_27 AC 61 ms
16,152 KB
testcase_28 AC 109 ms
20,500 KB
testcase_29 AC 16 ms
11,964 KB
testcase_30 AC 114 ms
20,908 KB
testcase_31 AC 81 ms
18,372 KB
testcase_32 AC 50 ms
14,772 KB
testcase_33 AC 110 ms
23,016 KB
testcase_34 AC 43 ms
14,424 KB
testcase_35 AC 109 ms
21,532 KB
testcase_36 AC 5 ms
10,068 KB
testcase_37 AC 5 ms
10,000 KB
testcase_38 AC 5 ms
9,956 KB
testcase_39 AC 5 ms
10,112 KB
testcase_40 AC 4 ms
9,820 KB
testcase_41 AC 171 ms
20,976 KB
testcase_42 AC 44 ms
12,948 KB
testcase_43 AC 76 ms
15,788 KB
testcase_44 AC 29 ms
11,724 KB
testcase_45 AC 75 ms
15,416 KB
testcase_46 AC 5 ms
9,916 KB
testcase_47 AC 5 ms
9,808 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define FOR(i,b,e) for (int i=(int)(b); i<(int)(e); i++)
#define ALL(x) (x).begin(), (x).end()

const double PI = acos(-1);
const double INF = 1e100;

vector<pair<int, double> > edges[200000];
double dist[200000];

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  int n, m, x, y;
  cin >> n >> m >> x >> y;
  --x, --y;

  vector<int> p(n), q(n);
  REP (i, n) cin >> p[i] >> q[i];

  REP (i, m) {
    int u, v;
    cin >> u >> v;
    --u, --v;
    double dist = hypot(abs(p[u]-p[v]), abs(q[u]-q[v]));
    edges[u].emplace_back(v, dist);
    edges[v].emplace_back(u, dist);
  }
  
  REP (i, 200000) dist[i] = INF;
  priority_queue<pair<double, int>, vector<pair<double, int>>, greater<pair<double, int>> > Q;
  dist[x] = 0.0;
  Q.emplace(dist[x], x);

  while (!Q.empty()) {
    int v;
    double w;
    tie(w, v) = Q.top();
    Q.pop();
    for (auto &[u, d]: edges[v]) {
      if (dist[v] + d < dist[u]) {
        dist[u] = dist[v] + d;
        Q.emplace(dist[u], u);
      }
    }
  }

  cout << fixed << setprecision(6) << dist[y] << endl;

  return 0;
}
0