結果

問題 No.1065 電柱 / Pole (Easy)
ユーザー rogi52rogi52
提出日時 2022-10-10 06:13:38
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 325 ms / 2,000 ms
コード長 1,269 bytes
コンパイル時間 2,449 ms
コンパイル使用メモリ 212,732 KB
実行使用メモリ 38,196 KB
最終ジャッジ日時 2023-09-06 07:28:29
合計ジャッジ時間 10,596 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 148 ms
18,868 KB
testcase_03 AC 179 ms
35,760 KB
testcase_04 AC 178 ms
35,748 KB
testcase_05 AC 130 ms
38,196 KB
testcase_06 AC 128 ms
35,312 KB
testcase_07 AC 42 ms
10,732 KB
testcase_08 AC 152 ms
32,376 KB
testcase_09 AC 15 ms
5,788 KB
testcase_10 AC 71 ms
16,012 KB
testcase_11 AC 48 ms
12,080 KB
testcase_12 AC 25 ms
10,536 KB
testcase_13 AC 148 ms
22,100 KB
testcase_14 AC 176 ms
26,156 KB
testcase_15 AC 202 ms
28,972 KB
testcase_16 AC 89 ms
17,456 KB
testcase_17 AC 223 ms
32,004 KB
testcase_18 AC 59 ms
13,684 KB
testcase_19 AC 209 ms
29,496 KB
testcase_20 AC 51 ms
10,588 KB
testcase_21 AC 68 ms
16,540 KB
testcase_22 AC 189 ms
28,556 KB
testcase_23 AC 3 ms
4,380 KB
testcase_24 AC 3 ms
4,376 KB
testcase_25 AC 23 ms
10,272 KB
testcase_26 AC 110 ms
18,892 KB
testcase_27 AC 108 ms
18,436 KB
testcase_28 AC 198 ms
30,012 KB
testcase_29 AC 17 ms
7,776 KB
testcase_30 AC 204 ms
33,116 KB
testcase_31 AC 141 ms
26,552 KB
testcase_32 AC 88 ms
16,280 KB
testcase_33 AC 204 ms
33,152 KB
testcase_34 AC 63 ms
13,460 KB
testcase_35 AC 212 ms
33,432 KB
testcase_36 AC 2 ms
4,376 KB
testcase_37 AC 4 ms
4,376 KB
testcase_38 AC 3 ms
4,380 KB
testcase_39 AC 3 ms
4,376 KB
testcase_40 AC 2 ms
4,376 KB
testcase_41 AC 325 ms
33,756 KB
testcase_42 AC 81 ms
12,588 KB
testcase_43 AC 154 ms
19,540 KB
testcase_44 AC 46 ms
9,264 KB
testcase_45 AC 149 ms
19,164 KB
testcase_46 AC 2 ms
4,376 KB
testcase_47 AC 1 ms
4,384 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;

// g <- pair < v , cost > 
template < class T >
vector< T > dijkstra(vector<vector<pair<int, T>>> &graph, int s) {
    T INF = numeric_limits< T >::max();
    vector<T> dist(graph.size(), INF);
    priority_queue<pair<T,int>, vector<pair<T,int>>, greater<pair<T,int>>> q;
    q.push({dist[s] = T(0), s});
    while(!q.empty()){
        auto [uc, ui] = q.top(); q.pop();
        if(uc != dist[ui]) continue;
        for(auto [vi, vc] : graph[ui]) if(dist[vi] > uc + vc) 
            q.push({dist[vi] = uc + vc, vi});
    }
    return dist;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    
    int N,M,X,Y; cin >> N >> M >> X >> Y; X--; Y--;
    using ld = long double;
    vector<pair<ld,ld>> pq(N);
    for(auto &[p, q] : pq) cin >> p >> q;
    vector<vector<pair<int,ld>>> G(N);
    rep(i,M) {
        int p,q; cin >> p >> q; p--; q--;
        auto [px, py] = pq[p];
        auto [qx, qy] = pq[q];
        ld dist = (px - qx) * (px - qx) + (py - qy) * (py - qy);
        dist = sqrtl(dist);
        G[p].push_back({q, dist});
        G[q].push_back({p, dist});
    }

    cout << fixed << setprecision(20) << dijkstra(G, X)[Y] << endl;
}
0