結果

問題 No.1065 電柱 / Pole (Easy)
ユーザー 👑 emthrmemthrm
提出日時 2020-05-29 21:51:55
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 185 ms / 2,000 ms
コード長 2,796 bytes
コンパイル時間 3,515 ms
コンパイル使用メモリ 211,176 KB
実行使用メモリ 35,584 KB
最終ジャッジ日時 2024-04-23 21:37:42
合計ジャッジ時間 8,150 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 85 ms
19,468 KB
testcase_03 AC 120 ms
32,096 KB
testcase_04 AC 112 ms
31,840 KB
testcase_05 AC 91 ms
31,840 KB
testcase_06 AC 92 ms
31,800 KB
testcase_07 AC 29 ms
11,904 KB
testcase_08 AC 110 ms
34,936 KB
testcase_09 AC 11 ms
6,400 KB
testcase_10 AC 49 ms
17,536 KB
testcase_11 AC 36 ms
13,056 KB
testcase_12 AC 20 ms
10,368 KB
testcase_13 AC 88 ms
21,412 KB
testcase_14 AC 97 ms
24,944 KB
testcase_15 AC 121 ms
28,024 KB
testcase_16 AC 54 ms
15,988 KB
testcase_17 AC 137 ms
30,020 KB
testcase_18 AC 37 ms
12,416 KB
testcase_19 AC 119 ms
28,716 KB
testcase_20 AC 31 ms
10,596 KB
testcase_21 AC 45 ms
14,592 KB
testcase_22 AC 106 ms
26,396 KB
testcase_23 AC 3 ms
5,376 KB
testcase_24 AC 3 ms
5,376 KB
testcase_25 AC 18 ms
9,856 KB
testcase_26 AC 60 ms
17,856 KB
testcase_27 AC 62 ms
17,448 KB
testcase_28 AC 111 ms
26,912 KB
testcase_29 AC 14 ms
7,424 KB
testcase_30 AC 122 ms
29,332 KB
testcase_31 AC 77 ms
22,628 KB
testcase_32 AC 50 ms
15,620 KB
testcase_33 AC 117 ms
29,340 KB
testcase_34 AC 42 ms
12,800 KB
testcase_35 AC 115 ms
29,664 KB
testcase_36 AC 2 ms
5,376 KB
testcase_37 AC 3 ms
5,376 KB
testcase_38 AC 2 ms
5,376 KB
testcase_39 AC 3 ms
5,376 KB
testcase_40 AC 2 ms
5,376 KB
testcase_41 AC 185 ms
35,584 KB
testcase_42 AC 46 ms
13,312 KB
testcase_43 AC 86 ms
20,592 KB
testcase_44 AC 30 ms
9,728 KB
testcase_45 AC 82 ms
20,096 KB
testcase_46 AC 1 ms
5,376 KB
testcase_47 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
using ll = long long;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-8;
const int MOD = 1000000007;
// const int MOD = 998244353;
const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
const int dy8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dx8[] = {0, -1, -1, -1, 0, 1, 1, 1};
template <typename T, typename U> inline bool chmax(T &a, U b) { return a < b ? (a = b, true) : false; }
template <typename T, typename U> inline bool chmin(T &a, U b) { return a > b ? (a = b, true) : false; }
struct IOSetup {
  IOSetup() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
  }
} iosetup;

using CostType = double;
struct Edge {
  int src, dst; CostType cost;
  Edge(int src, int dst, CostType cost = 0) : src(src), dst(dst), cost(cost) {}
  inline bool operator<(const Edge &x) const {
    return cost != x.cost ? cost < x.cost : dst != x.dst ? dst < x.dst : src < x.src;
  }
  inline bool operator<=(const Edge &x) const { return !(x < *this); }
  inline bool operator>(const Edge &x) const { return x < *this; }
  inline bool operator>=(const Edge &x) const { return !(*this < x); }
};

struct Dijkstra {
  using Pci = pair<CostType, int>;

  Dijkstra(const vector<vector<Edge>> &graph, const CostType CINF) : graph(graph), CINF(CINF) {}

  vector<CostType> build(int s) {
    int n = graph.size();
    vector<CostType> dist(n, CINF);
    dist[s] = 0;
    prev.assign(n, -1);
    priority_queue<Pci, vector<Pci>, greater<Pci>> que;
    que.emplace(0, s);
    while (!que.empty()) {
      CostType cost; int ver; tie(cost, ver) = que.top(); que.pop();
      if (dist[ver] < cost) continue;
      for (const Edge &e : graph[ver]) {
        if (dist[e.dst] > dist[ver] + e.cost) {
          dist[e.dst] = dist[ver] + e.cost;
          prev[e.dst] = ver;
          que.emplace(dist[e.dst], e.dst);
        }
      }
    }
    return dist;
  }

  vector<int> build_path(int t) {
    vector<int> res;
    for (; t != -1; t = prev[t]) res.emplace_back(t);
    reverse(ALL(res));
    return res;
  }

private:
  vector<vector<Edge>> graph;
  const CostType CINF;
  vector<int> prev;
};

int main() {
  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];
  vector<vector<Edge>> graph(n);
  while (m--) {
    int P, Q; cin >> P >> Q; --P; --Q;
    double dist = sqrt((p[P] - p[Q]) * (p[P] - p[Q]) + (q[P] - q[Q]) * (q[P] - q[Q]));
    graph[P].emplace_back(P, Q, dist);
    graph[Q].emplace_back(Q, P, dist);
  }
  Dijkstra dij(graph, LINF);
  cout << dij.build(x)[y] << '\n';
  return 0;
}
0