結果

問題 No.1065 電柱 / Pole (Easy)
ユーザー rogi52
提出日時 2022-10-10 06:13:38
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 317 ms / 2,000 ms
コード長 1,269 bytes
コンパイル時間 2,317 ms
コンパイル使用メモリ 209,884 KB
最終ジャッジ日時 2025-02-08 01:08:56
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 46
権限があれば一括ダウンロードができます

ソースコード

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