結果

問題 No.1065 電柱 / Pole (Easy)
ユーザー finefine
提出日時 2020-05-29 21:37:30
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 246 ms / 2,000 ms
コード長 1,891 bytes
コンパイル時間 1,898 ms
コンパイル使用メモリ 175,484 KB
実行使用メモリ 32,012 KB
最終ジャッジ日時 2024-04-23 20:34:57
合計ジャッジ時間 7,494 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 104 ms
17,664 KB
testcase_03 AC 170 ms
32,012 KB
testcase_04 AC 158 ms
31,504 KB
testcase_05 AC 120 ms
31,368 KB
testcase_06 AC 129 ms
31,372 KB
testcase_07 AC 40 ms
10,496 KB
testcase_08 AC 146 ms
29,568 KB
testcase_09 AC 14 ms
5,760 KB
testcase_10 AC 61 ms
15,104 KB
testcase_11 AC 45 ms
11,520 KB
testcase_12 AC 25 ms
11,008 KB
testcase_13 AC 117 ms
21,404 KB
testcase_14 AC 135 ms
24,824 KB
testcase_15 AC 160 ms
27,204 KB
testcase_16 AC 69 ms
17,276 KB
testcase_17 AC 178 ms
29,244 KB
testcase_18 AC 52 ms
13,720 KB
testcase_19 AC 163 ms
27,668 KB
testcase_20 AC 39 ms
10,100 KB
testcase_21 AC 63 ms
16,720 KB
testcase_22 AC 151 ms
26,116 KB
testcase_23 AC 3 ms
5,376 KB
testcase_24 AC 3 ms
5,376 KB
testcase_25 AC 23 ms
10,496 KB
testcase_26 AC 86 ms
18,056 KB
testcase_27 AC 85 ms
18,272 KB
testcase_28 AC 155 ms
27,672 KB
testcase_29 AC 16 ms
8,320 KB
testcase_30 AC 163 ms
30,028 KB
testcase_31 AC 114 ms
23,652 KB
testcase_32 AC 70 ms
15,796 KB
testcase_33 AC 166 ms
30,588 KB
testcase_34 AC 50 ms
13,452 KB
testcase_35 AC 168 ms
30,164 KB
testcase_36 AC 3 ms
5,376 KB
testcase_37 AC 3 ms
5,376 KB
testcase_38 AC 2 ms
5,376 KB
testcase_39 AC 4 ms
5,376 KB
testcase_40 AC 2 ms
5,376 KB
testcase_41 AC 246 ms
30,976 KB
testcase_42 AC 66 ms
12,160 KB
testcase_43 AC 114 ms
18,304 KB
testcase_44 AC 35 ms
8,960 KB
testcase_45 AC 100 ms
17,664 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;

using ll = long double;

constexpr char newl = '\n';

struct State {
    int at;
    ll cost;
    //int prev;
    State(int at, ll cost/*, int prev*/) : at(at), cost(cost)/*, prev(prev)*/ {}
    bool operator>(const State& s) const {
        return cost > s.cost;
    }
};

struct Edge {
    int to;
    ll cost;
    Edge(int to, ll cost) : to(to), cost(cost) {}
};

using Graph = vector< vector<Edge> >; //隣接リスト

const ll INF = 1e15;
//const int NONE = -1;

//sは始点、mincは最短経路のコスト、prevsは最短経路をたどる際の前の頂点
void dijkstra(int s, const Graph& graph, vector<ll>& minc/*, vector<int>& prevs*/){
    minc.assign(graph.size(), INF);
    //prevs.assign(graph.size(), NONE);

    priority_queue<State, vector<State>, greater<State> > pq;
    pq.emplace(s, 0/*, NONE*/);
    minc[s] = 0;

    while(!pq.empty()) {
        State cur = pq.top();
        pq.pop();
        if (minc[cur.at] < cur.cost) continue;

        for(const Edge& e : graph[cur.at]) {
            ll cost = cur.cost + e.cost;
            if (minc[e.to] <= cost) continue;
            minc[e.to] = cost;
            //prevs[e.to] = cur.at;
            pq.emplace(e.to, cost/*, cur.at*/);
        }
    }
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    int n, m;
    cin >> n >> m;

    int x, y;
    cin >> x >> y;
    --x; --y;

    vector<double> p(n), q(n);
    for (int i = 0; i < n; i++) {
        cin >> p[i] >> q[i];
    }

    Graph g(n);

    for (int i = 0; i < m; i++) {
        int u, v;
        cin >> u >> v;
        --u; --v;

        ll cost = hypot(p[u] - p[v], q[u] - q[v]);
        g[u].emplace_back(v, cost);
        g[v].emplace_back(u, cost);
    }

    vector<ll> minc;
    dijkstra(x, g, minc);

    cout << fixed << setprecision(15) << minc[y] << newl;
    return 0;
}
0