結果

問題 No.1065 電柱 / Pole (Easy)
ユーザー hedwig100hedwig100
提出日時 2020-05-29 21:56:55
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 304 ms / 2,000 ms
コード長 1,498 bytes
コンパイル時間 1,515 ms
コンパイル使用メモリ 175,440 KB
実行使用メモリ 21,264 KB
最終ジャッジ日時 2024-04-23 21:59:18
合計ジャッジ時間 8,107 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,812 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 130 ms
12,456 KB
testcase_03 AC 205 ms
21,264 KB
testcase_04 AC 200 ms
19,972 KB
testcase_05 AC 171 ms
21,088 KB
testcase_06 AC 166 ms
20,852 KB
testcase_07 AC 55 ms
7,808 KB
testcase_08 AC 211 ms
20,436 KB
testcase_09 AC 18 ms
6,940 KB
testcase_10 AC 93 ms
11,008 KB
testcase_11 AC 64 ms
8,704 KB
testcase_12 AC 42 ms
7,040 KB
testcase_13 AC 132 ms
13,884 KB
testcase_14 AC 199 ms
15,936 KB
testcase_15 AC 233 ms
17,516 KB
testcase_16 AC 96 ms
11,048 KB
testcase_17 AC 198 ms
18,644 KB
testcase_18 AC 66 ms
8,960 KB
testcase_19 AC 189 ms
17,888 KB
testcase_20 AC 51 ms
7,316 KB
testcase_21 AC 81 ms
10,368 KB
testcase_22 AC 177 ms
16,828 KB
testcase_23 AC 3 ms
6,940 KB
testcase_24 AC 4 ms
6,940 KB
testcase_25 AC 39 ms
6,940 KB
testcase_26 AC 104 ms
11,812 KB
testcase_27 AC 107 ms
11,752 KB
testcase_28 AC 179 ms
17,416 KB
testcase_29 AC 23 ms
6,944 KB
testcase_30 AC 191 ms
18,556 KB
testcase_31 AC 127 ms
15,048 KB
testcase_32 AC 81 ms
10,600 KB
testcase_33 AC 183 ms
19,860 KB
testcase_34 AC 69 ms
8,960 KB
testcase_35 AC 187 ms
19,016 KB
testcase_36 AC 3 ms
6,940 KB
testcase_37 AC 4 ms
6,940 KB
testcase_38 AC 3 ms
6,940 KB
testcase_39 AC 3 ms
6,940 KB
testcase_40 AC 2 ms
6,940 KB
testcase_41 AC 304 ms
20,832 KB
testcase_42 AC 81 ms
8,832 KB
testcase_43 AC 141 ms
12,800 KB
testcase_44 AC 48 ms
6,948 KB
testcase_45 AC 134 ms
12,544 KB
testcase_46 AC 2 ms
6,944 KB
testcase_47 AC 2 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i ++)
using namespace std;
typedef long long ll;
typedef pair<double,int> PL;
typedef pair<int,int> P;
const int INF = 1e9;
const ll MOD = 1e12;
const double eps = 1e-6;

vector<double> dijkstra(int n, vector<vector<PL>>& G,int& s) {
    vector<double> dist(n,(double)INF);
    dist[s] = 0.0;

    priority_queue<PL,vector<PL>,greater<P>> q;
    q.push({0.0,s});

    while (!q.empty()) {
        PL p = q.top(); q.pop();
        double d = p.first;
        int v = p.second;
        if (dist[v] < d) continue;
        for (PL p: G[v]) {
            double cost = p.first;
            int e = p.second;
            if (dist[e] > dist[v] + cost) {
                dist[e] = dist[v] + cost;
                q.push({dist[e],e});
            }
        }  
    }
    return dist;
}

int main() {
    int N,M,X,Y; cin >> N >> M >> X >> Y; X--;Y--;
    vector<pair<int,int>> point(N);
    rep(i,N) cin >> point[i].first >> point[i].second;
    vector<vector<PL>> G(N);
    auto dist = [&](int x,int y){return sqrt((point[x].first - point[y].first) * (point[x].first - point[y].first) + (point[x].second - point[y].second) * (point[x].second - point[y].second));};
    rep(_,M){
        int p,q; cin >> p >> q;
        p --; q --;
        double d = dist(p,q);
        G[p].push_back(PL(d,q));
        G[q].push_back(PL(d,p));
    }
    vector<double> distance = dijkstra(N,G,X);
    double ans = distance[Y];
    printf("%0.10f\n",ans);
}
0