結果

問題 No.1065 電柱 / Pole (Easy)
ユーザー KoDKoD
提出日時 2020-05-29 21:29:49
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 327 ms / 2,000 ms
コード長 2,340 bytes
コンパイル時間 1,228 ms
コンパイル使用メモリ 112,676 KB
実行使用メモリ 22,492 KB
最終ジャッジ日時 2024-04-23 20:17:11
合計ジャッジ時間 8,563 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 168 ms
13,312 KB
testcase_03 AC 244 ms
21,460 KB
testcase_04 AC 243 ms
21,460 KB
testcase_05 AC 193 ms
21,260 KB
testcase_06 AC 193 ms
21,336 KB
testcase_07 AC 70 ms
8,320 KB
testcase_08 AC 268 ms
21,888 KB
testcase_09 AC 23 ms
5,376 KB
testcase_10 AC 125 ms
11,648 KB
testcase_11 AC 85 ms
9,088 KB
testcase_12 AC 49 ms
7,296 KB
testcase_13 AC 179 ms
14,560 KB
testcase_14 AC 208 ms
16,956 KB
testcase_15 AC 251 ms
18,608 KB
testcase_16 AC 118 ms
11,552 KB
testcase_17 AC 279 ms
19,856 KB
testcase_18 AC 88 ms
9,216 KB
testcase_19 AC 248 ms
19,132 KB
testcase_20 AC 66 ms
8,064 KB
testcase_21 AC 94 ms
10,752 KB
testcase_22 AC 236 ms
17,912 KB
testcase_23 AC 4 ms
5,376 KB
testcase_24 AC 5 ms
5,376 KB
testcase_25 AC 47 ms
7,040 KB
testcase_26 AC 119 ms
12,580 KB
testcase_27 AC 111 ms
12,424 KB
testcase_28 AC 188 ms
18,232 KB
testcase_29 AC 25 ms
6,144 KB
testcase_30 AC 208 ms
19,872 KB
testcase_31 AC 148 ms
16,028 KB
testcase_32 AC 91 ms
11,320 KB
testcase_33 AC 210 ms
20,412 KB
testcase_34 AC 78 ms
9,476 KB
testcase_35 AC 215 ms
20,060 KB
testcase_36 AC 3 ms
5,376 KB
testcase_37 AC 4 ms
5,376 KB
testcase_38 AC 3 ms
5,376 KB
testcase_39 AC 3 ms
5,376 KB
testcase_40 AC 2 ms
5,376 KB
testcase_41 AC 327 ms
22,492 KB
testcase_42 AC 91 ms
9,344 KB
testcase_43 AC 162 ms
13,696 KB
testcase_44 AC 58 ms
7,168 KB
testcase_45 AC 155 ms
13,184 KB
testcase_46 AC 2 ms
5,376 KB
testcase_47 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <numeric>
#include <cmath>
#include <queue>
#include <iomanip>

template <class T, class U>
inline bool chmin(T &lhs, const U &rhs) {
  if (lhs > rhs) {
    lhs = rhs;
    return true;
  }
  return false;
}

template <class T, class U>
inline bool chmax(T &lhs, const U &rhs) {
  if (lhs < rhs) {
    lhs = rhs;
    return true;
  }
  return false;
}

// [l, r) from l to r
struct range {
  struct itr {
    int i;
    constexpr itr(int i_): i(i_) { }
    constexpr void operator ++ () { ++i; }
    constexpr int operator * () const { return i; }
    constexpr bool operator != (itr x) const { return i != x.i; }
  };
  const itr l, r;
  constexpr range(int l_, int r_): l(l_), r(std::max(l_, r_)) { }
  constexpr itr begin() const { return l; }
  constexpr itr end() const { return r; }
};

// [l, r) from r to l
struct revrange {
  struct itr {
    int i;
    constexpr itr(int i_): i(i_) { }
    constexpr void operator ++ () { --i; }
    constexpr int operator * () const { return i; }
    constexpr bool operator != (itr x) const { return i != x.i; }
  };
  const itr l, r;
  constexpr revrange(int l_, int r_): l(l_ - 1), r(std::max(l_, r_) - 1) { }
  constexpr itr begin() const { return r; }
  constexpr itr end() const { return l; }
};

int main() {
  int N, M;
  std::cin >> N >> M;
  int S, G;
  std::cin >> S >> G;
  --S; --G;
  std::vector<double> X(N), Y(N);
  for (int i: range(0, N)) {
    std::cin >> X[i] >> Y[i];
  }
  std::vector<std::vector<std::pair<int, double>>> graph(N);
  for (int i: range(0, M)) {
    int x, y;
    std::cin >> x >> y;
    --x; --y;
    double d = std::hypot(X[x] - X[y], Y[x] - Y[y]);
    graph[x].emplace_back(y, d);
    graph[y].emplace_back(x, d);
  }
  std::vector<double> dist(N, 1e9);
  using state = std::pair<double, int>;
  std::priority_queue<state, std::vector<state>, std::greater<state>> que;
  dist[S] = 0;
  que.emplace(dist[S], S);
  while (!que.empty()) {
    auto [d, u] = que.top();
    que.pop();
    if (d > dist[u]) {
      continue;
    }
    for (auto e: graph[u]) {
      if (chmin(dist[e.first], dist[u] + e.second)) {
        que.emplace(dist[e.first], e.first);
      }
    }
  }
  std::cout << std::fixed << std::setprecision(20);
  std::cout << dist[G] << '\n';
  return 0;
}
0