結果

問題 No.1065 電柱 / Pole (Easy)
ユーザー iqueue02iqueue02
提出日時 2020-05-30 23:28:14
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 462 ms / 2,000 ms
コード長 1,229 bytes
コンパイル時間 2,281 ms
コンパイル使用メモリ 207,864 KB
実行使用メモリ 36,436 KB
最終ジャッジ日時 2024-04-26 06:02:54
合計ジャッジ時間 12,549 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 210 ms
19,540 KB
testcase_03 AC 324 ms
34,232 KB
testcase_04 AC 288 ms
33,876 KB
testcase_05 AC 245 ms
33,496 KB
testcase_06 AC 242 ms
33,748 KB
testcase_07 AC 79 ms
11,220 KB
testcase_08 AC 310 ms
32,724 KB
testcase_09 AC 27 ms
5,972 KB
testcase_10 AC 140 ms
16,468 KB
testcase_11 AC 93 ms
12,260 KB
testcase_12 AC 57 ms
10,880 KB
testcase_13 AC 209 ms
24,660 KB
testcase_14 AC 241 ms
30,040 KB
testcase_15 AC 282 ms
31,444 KB
testcase_16 AC 130 ms
18,056 KB
testcase_17 AC 309 ms
33,492 KB
testcase_18 AC 90 ms
14,548 KB
testcase_19 AC 291 ms
31,576 KB
testcase_20 AC 76 ms
11,092 KB
testcase_21 AC 109 ms
16,840 KB
testcase_22 AC 270 ms
31,060 KB
testcase_23 AC 4 ms
5,376 KB
testcase_24 AC 5 ms
5,376 KB
testcase_25 AC 46 ms
10,496 KB
testcase_26 AC 150 ms
19,028 KB
testcase_27 AC 153 ms
20,056 KB
testcase_28 AC 273 ms
31,572 KB
testcase_29 AC 30 ms
7,920 KB
testcase_30 AC 298 ms
32,468 KB
testcase_31 AC 195 ms
25,048 KB
testcase_32 AC 125 ms
17,108 KB
testcase_33 AC 291 ms
36,436 KB
testcase_34 AC 97 ms
14,420 KB
testcase_35 AC 295 ms
33,368 KB
testcase_36 AC 3 ms
5,376 KB
testcase_37 AC 5 ms
5,376 KB
testcase_38 AC 3 ms
5,376 KB
testcase_39 AC 4 ms
5,376 KB
testcase_40 AC 3 ms
5,376 KB
testcase_41 AC 462 ms
34,004 KB
testcase_42 AC 119 ms
12,752 KB
testcase_43 AC 225 ms
19,544 KB
testcase_44 AC 73 ms
9,556 KB
testcase_45 AC 213 ms
19,412 KB
testcase_46 AC 2 ms
5,376 KB
testcase_47 AC 2 ms
5,376 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