結果

問題 No.1065 電柱 / Pole (Easy)
ユーザー iqueue02iqueue02
提出日時 2020-05-30 23:28:14
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 398 ms / 2,000 ms
コード長 1,229 bytes
コンパイル時間 3,883 ms
コンパイル使用メモリ 212,424 KB
実行使用メモリ 37,124 KB
最終ジャッジ日時 2023-08-08 13:16:23
合計ジャッジ時間 14,107 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 189 ms
19,192 KB
testcase_03 AC 278 ms
36,656 KB
testcase_04 AC 277 ms
36,412 KB
testcase_05 AC 223 ms
36,560 KB
testcase_06 AC 224 ms
37,124 KB
testcase_07 AC 77 ms
10,848 KB
testcase_08 AC 289 ms
32,424 KB
testcase_09 AC 26 ms
5,740 KB
testcase_10 AC 130 ms
16,900 KB
testcase_11 AC 89 ms
12,100 KB
testcase_12 AC 48 ms
10,572 KB
testcase_13 AC 191 ms
24,196 KB
testcase_14 AC 229 ms
30,684 KB
testcase_15 AC 266 ms
31,368 KB
testcase_16 AC 122 ms
17,692 KB
testcase_17 AC 294 ms
35,404 KB
testcase_18 AC 84 ms
14,316 KB
testcase_19 AC 275 ms
32,480 KB
testcase_20 AC 69 ms
10,896 KB
testcase_21 AC 99 ms
16,788 KB
testcase_22 AC 246 ms
31,728 KB
testcase_23 AC 3 ms
4,380 KB
testcase_24 AC 4 ms
4,376 KB
testcase_25 AC 43 ms
10,272 KB
testcase_26 AC 136 ms
18,880 KB
testcase_27 AC 146 ms
19,776 KB
testcase_28 AC 254 ms
32,368 KB
testcase_29 AC 27 ms
7,812 KB
testcase_30 AC 261 ms
33,496 KB
testcase_31 AC 192 ms
28,640 KB
testcase_32 AC 116 ms
16,840 KB
testcase_33 AC 262 ms
36,764 KB
testcase_34 AC 88 ms
13,888 KB
testcase_35 AC 260 ms
34,032 KB
testcase_36 AC 3 ms
4,376 KB
testcase_37 AC 4 ms
4,384 KB
testcase_38 AC 3 ms
4,380 KB
testcase_39 AC 4 ms
4,380 KB
testcase_40 AC 2 ms
4,380 KB
testcase_41 AC 398 ms
34,044 KB
testcase_42 AC 106 ms
12,612 KB
testcase_43 AC 197 ms
19,404 KB
testcase_44 AC 69 ms
9,260 KB
testcase_45 AC 193 ms
18,916 KB
testcase_46 AC 1 ms
4,380 KB
testcase_47 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n);i++)
#define sz(x) int(x.size())
typedef long long ll;
typedef pair<int,int> P;
constexpr int INF = 2e9;
typedef long double ld;
int main() {
  int n, m;
  cin >> n >> m;
  int x, y;
  cin >> x >> y;
  x--; y--;
  vector<pair<ld, ld>> p;
  rep(i,n) {
    ld a, b;
    cin >> a >> b;
    p.emplace_back(make_pair(a, b));
  }
  vector<vector<pair<int, ld>>> g(n);
  rep(i,m) {
    int u, v;
    cin >> u >> v;
    u--; v--;
    ld s = (p[u].first - p[v].first), t = (p[u].second - p[v].second);
    ld d = sqrt((s * s) + (t * t));
    g[u].emplace_back(make_pair(v, d));
    g[v].emplace_back(make_pair(u, d));
  }

  vector<ld> dist(n, INF);
  priority_queue<pair<ld, int>, vector<pair<ld, int>>, greater<pair<ld, int>>> pq;
  pq.push(make_pair(0.0, x));
  dist[x] = 0.0;

  while (!pq.empty()) {
    auto t = pq.top();
    pq.pop();
    int u = t.second;
    if (t.first > dist[u]) continue;
    for (auto e : g[u]) {
      ld cost = e.second;
      int v = e.first;
      if (dist[v] > dist[u] + cost) {
        dist[v] = dist[u] + cost;
        pq.push(make_pair(dist[v], v));
      } 
    }
  }

  printf("%.12Lf\n", dist[y]);
  return 0;
}
0