結果

問題 No.1065 電柱 / Pole (Easy)
ユーザー firiexpfiriexp
提出日時 2020-05-29 21:39:22
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 252 ms / 2,000 ms
コード長 1,634 bytes
コンパイル時間 1,226 ms
コンパイル使用メモリ 115,268 KB
実行使用メモリ 20,992 KB
最終ジャッジ日時 2024-04-23 20:37:56
合計ジャッジ時間 6,630 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 111 ms
12,544 KB
testcase_03 AC 137 ms
20,292 KB
testcase_04 AC 135 ms
20,164 KB
testcase_05 AC 98 ms
20,164 KB
testcase_06 AC 98 ms
20,160 KB
testcase_07 AC 31 ms
7,936 KB
testcase_08 AC 114 ms
20,480 KB
testcase_09 AC 12 ms
5,376 KB
testcase_10 AC 51 ms
11,008 KB
testcase_11 AC 35 ms
8,576 KB
testcase_12 AC 28 ms
7,168 KB
testcase_13 AC 114 ms
13,952 KB
testcase_14 AC 131 ms
15,948 KB
testcase_15 AC 155 ms
17,776 KB
testcase_16 AC 72 ms
11,200 KB
testcase_17 AC 173 ms
18,900 KB
testcase_18 AC 51 ms
8,960 KB
testcase_19 AC 158 ms
18,140 KB
testcase_20 AC 37 ms
7,552 KB
testcase_21 AC 63 ms
10,368 KB
testcase_22 AC 147 ms
16,960 KB
testcase_23 AC 3 ms
5,376 KB
testcase_24 AC 3 ms
5,376 KB
testcase_25 AC 25 ms
6,912 KB
testcase_26 AC 79 ms
12,068 KB
testcase_27 AC 81 ms
11,884 KB
testcase_28 AC 150 ms
17,548 KB
testcase_29 AC 16 ms
6,144 KB
testcase_30 AC 158 ms
18,812 KB
testcase_31 AC 105 ms
15,304 KB
testcase_32 AC 61 ms
10,864 KB
testcase_33 AC 156 ms
19,348 KB
testcase_34 AC 53 ms
9,216 KB
testcase_35 AC 157 ms
19,140 KB
testcase_36 AC 2 ms
5,376 KB
testcase_37 AC 3 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 252 ms
20,992 KB
testcase_42 AC 59 ms
8,960 KB
testcase_43 AC 115 ms
12,928 KB
testcase_44 AC 35 ms
7,040 KB
testcase_45 AC 115 ms
12,544 KB
testcase_46 AC 2 ms
5,376 KB
testcase_47 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

template <typename T>
struct edge {
    int from, to; T cost;
    edge(int to, T cost) : from(-1), to(to), cost(cost) {}
    edge(int from, int to, T cost) : from(from), to(to), cost(cost) {}
};

template <typename T>
vector<T> dijkstra(int s,vector<vector<edge<T>>> &G){
    auto n = G.size();
    vector<T> d(n, INF<T>);
    priority_queue<pair<T, int>,vector<pair<T, int>>,greater<>> Q;
    d[s] = 0;
    Q.emplace(0, s);
    while(!Q.empty()){
        T cost; int i;
        tie(cost, i) = Q.top(); Q.pop();
        if(d[i] < cost) continue;
        for (auto &&e : G[i]) {
            auto cost2 = cost + e.cost;
            if(d[e.to] <= cost2) continue;
            d[e.to] = cost2;
            Q.emplace(d[e.to], e.to);
        }
    }
    return d;
}

int main() {
    int n, m, x, y;
    cin >> n >> m >> x >> y;
    x--; y--;
    vector<int> p(n), q(n);
    for (int i = 0; i < n; ++i) {
        scanf("%d %d", &p[i], &q[i]);
    }
    vector<vector<edge<double>>> G(n);
    for (int i = 0; i < m; ++i) {
        int a, b;
        scanf("%d %d", &a, &b);
        a--; b--;
        G[a].emplace_back(b, hypot(p[a]-p[b], q[a]-q[b]));
        G[b].emplace_back(a, hypot(p[a]-p[b], q[a]-q[b]));
    }
    printf("%.10lf\n", dijkstra(x, G)[y]);
    return 0;
}
0