結果

問題 No.1065 電柱 / Pole (Easy)
ユーザー knshnbknshnb
提出日時 2020-05-29 22:19:44
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 241 ms / 2,000 ms
コード長 1,944 bytes
コンパイル時間 2,389 ms
コンパイル使用メモリ 206,960 KB
実行使用メモリ 25,424 KB
最終ジャッジ日時 2024-04-23 23:07:21
合計ジャッジ時間 7,936 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 107 ms
13,228 KB
testcase_03 AC 143 ms
24,568 KB
testcase_04 AC 137 ms
24,716 KB
testcase_05 AC 99 ms
25,424 KB
testcase_06 AC 100 ms
24,092 KB
testcase_07 AC 29 ms
8,448 KB
testcase_08 AC 104 ms
21,892 KB
testcase_09 AC 11 ms
6,944 KB
testcase_10 AC 47 ms
11,648 KB
testcase_11 AC 33 ms
9,216 KB
testcase_12 AC 40 ms
9,040 KB
testcase_13 AC 122 ms
15,348 KB
testcase_14 AC 132 ms
16,688 KB
testcase_15 AC 156 ms
20,756 KB
testcase_16 AC 81 ms
12,240 KB
testcase_17 AC 173 ms
19,496 KB
testcase_18 AC 61 ms
10,480 KB
testcase_19 AC 156 ms
19,028 KB
testcase_20 AC 39 ms
7,936 KB
testcase_21 AC 74 ms
11,924 KB
testcase_22 AC 147 ms
17,552 KB
testcase_23 AC 4 ms
6,940 KB
testcase_24 AC 4 ms
6,940 KB
testcase_25 AC 35 ms
7,832 KB
testcase_26 AC 87 ms
12,944 KB
testcase_27 AC 94 ms
13,092 KB
testcase_28 AC 162 ms
21,200 KB
testcase_29 AC 20 ms
6,944 KB
testcase_30 AC 163 ms
21,540 KB
testcase_31 AC 104 ms
15,672 KB
testcase_32 AC 69 ms
11,084 KB
testcase_33 AC 157 ms
20,948 KB
testcase_34 AC 61 ms
10,780 KB
testcase_35 AC 168 ms
19,836 KB
testcase_36 AC 3 ms
6,944 KB
testcase_37 AC 3 ms
6,944 KB
testcase_38 AC 3 ms
6,940 KB
testcase_39 AC 3 ms
6,944 KB
testcase_40 AC 2 ms
6,944 KB
testcase_41 AC 241 ms
22,556 KB
testcase_42 AC 55 ms
9,344 KB
testcase_43 AC 110 ms
13,568 KB
testcase_44 AC 32 ms
7,168 KB
testcase_45 AC 107 ms
13,440 KB
testcase_46 AC 2 ms
6,944 KB
testcase_47 AC 2 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>  // clang-format off
using Int = long long;
#define REP_(i, a_, b_, a, b, ...) for (Int i = (a), lim##i = (b); i < lim##i; i++)
#define REP(i, ...) REP_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
struct SetupIO { SetupIO() { std::cin.tie(nullptr), std::ios::sync_with_stdio(false), std::cout << std::fixed << std::setprecision(13); } } setup_io;
#ifndef dump
#define dump(...)
#endif  // clang-format on

/**
 *    author:  knshnb
 *    created: Fri May 29 22:12:23 JST 2020
 **/

template <class T, bool directed = true> struct Dijkstra {
    struct Edge {
        int to;
        T cost;
    };
    std::vector<std::vector<Edge>> g;
    Dijkstra(int n) : g(n) {}
    void add_edge(int u, int v, T cost) {
        g[u].push_back({v, cost});
        if (!directed) g[v].push_back({u, cost});
    }
    std::vector<T> run(int s) {
        std::vector<T> dist(g.size(), std::numeric_limits<T>::max() / 2);
        // {d, v}
        std::priority_queue<std::pair<T, int>, std::vector<std::pair<T, int>>, std::greater<std::pair<T, int>>> q;
        q.push({0, s});
        while (!q.empty()) {
            std::pair<T, int> p = q.top();
            q.pop();
            int v = p.second;
            if (dist[v] <= p.first) continue;
            dist[v] = p.first;
            for (const Edge& e : g[v]) {
                if (dist[e.to] <= p.first + e.cost) continue;  // 定数倍枝刈り
                q.emplace(p.first + e.cost, e.to);
            }
        }
        return dist;
    }
};

signed main() {
    Int n, m, x, y;
    std::cin >> n >> m >> x >> y;
    x--, y--;
    Dijkstra<double, false> g(n);
    std::vector<Int> p(n), q(n);
    REP(i, n) std::cin >> p[i] >> q[i];
    REP(i, m) {
        Int u, v;
        std::cin >> u >> v;
        u--, v--;
        double dx = p[u] - p[v], dy = q[u] - q[v];
        g.add_edge(u, v, sqrt(dx * dx + dy * dy));
    }
    std::cout << g.run(x)[y] << std::endl;
}
0