結果

問題 No.1065 電柱 / Pole (Easy)
ユーザー veqccveqcc
提出日時 2020-05-29 22:14:20
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 284 ms / 2,000 ms
コード長 1,603 bytes
コンパイル時間 1,323 ms
コンパイル使用メモリ 114,868 KB
実行使用メモリ 21,316 KB
最終ジャッジ日時 2024-04-23 22:55:33
合計ジャッジ時間 7,377 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 131 ms
12,288 KB
testcase_03 AC 197 ms
20,544 KB
testcase_04 AC 197 ms
21,316 KB
testcase_05 AC 173 ms
20,424 KB
testcase_06 AC 169 ms
19,804 KB
testcase_07 AC 60 ms
7,936 KB
testcase_08 AC 224 ms
20,352 KB
testcase_09 AC 20 ms
6,940 KB
testcase_10 AC 94 ms
11,136 KB
testcase_11 AC 66 ms
8,576 KB
testcase_12 AC 46 ms
7,168 KB
testcase_13 AC 140 ms
13,764 KB
testcase_14 AC 152 ms
15,936 KB
testcase_15 AC 175 ms
17,520 KB
testcase_16 AC 88 ms
11,096 KB
testcase_17 AC 192 ms
18,648 KB
testcase_18 AC 65 ms
8,832 KB
testcase_19 AC 180 ms
17,888 KB
testcase_20 AC 51 ms
7,440 KB
testcase_21 AC 82 ms
10,240 KB
testcase_22 AC 165 ms
16,708 KB
testcase_23 AC 4 ms
6,944 KB
testcase_24 AC 4 ms
6,940 KB
testcase_25 AC 38 ms
6,940 KB
testcase_26 AC 94 ms
11,940 KB
testcase_27 AC 101 ms
11,756 KB
testcase_28 AC 166 ms
17,292 KB
testcase_29 AC 23 ms
6,940 KB
testcase_30 AC 181 ms
18,552 KB
testcase_31 AC 137 ms
15,052 KB
testcase_32 AC 76 ms
10,732 KB
testcase_33 AC 177 ms
20,120 KB
testcase_34 AC 70 ms
8,960 KB
testcase_35 AC 176 ms
18,892 KB
testcase_36 AC 3 ms
6,944 KB
testcase_37 AC 4 ms
6,940 KB
testcase_38 AC 3 ms
6,944 KB
testcase_39 AC 3 ms
6,944 KB
testcase_40 AC 2 ms
6,940 KB
testcase_41 AC 284 ms
21,124 KB
testcase_42 AC 75 ms
8,832 KB
testcase_43 AC 136 ms
12,800 KB
testcase_44 AC 50 ms
6,944 KB
testcase_45 AC 142 ms
12,544 KB
testcase_46 AC 2 ms
6,940 KB
testcase_47 AC 1 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <functional>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;
const ll MOD = 1000000007LL;
typedef pair <double, int> P;

vector<double> dijkstra(vector<vector<P>> &edge, int s) {
    vector <double> dist(edge.size(), 1e18);
    priority_queue <P, vector<P>, greater<P>> q;
    q.push({0, s});
    dist[s] = 0;
    while (!q.empty()) {
        P p = q.top();
        q.pop();
        int cur = p.second;
        double cost = p.first;
        if (dist[cur] < cost) continue;
        for (P nxt : edge[cur]) {
            int next_node = nxt.second;
            double cost_sum = cost + nxt.first;
            if (dist[next_node] > cost_sum) {
                dist[next_node] = cost_sum;
                q.push({cost_sum, next_node});
            }
        }
    }

    return dist;
}

int main() {
    int n, m;
    cin >> n >> m;

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

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

    vector<vector<P>> edge(n);
    for (int i = 0; i < m; i++) {
        int u, v;
        cin >> u >> v;
        u--; v--;
        double diff = sqrt((p[u] - p[v]) * (p[u] - p[v]) + (q[u] - q[v]) * (q[u] - q[v]));
        edge[u].push_back({diff, v});
        edge[v].push_back({diff, u});
    }

    auto dist = dijkstra(edge, x);

    cout << fixed << setprecision(6) << dist[y] << endl;
    return 0;
}
0