結果

問題 No.1065 電柱 / Pole (Easy)
ユーザー KKT89KKT89
提出日時 2020-06-20 10:41:00
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 222 ms / 2,000 ms
コード長 1,603 bytes
コンパイル時間 1,182 ms
コンパイル使用メモリ 114,284 KB
実行使用メモリ 22,416 KB
最終ジャッジ日時 2024-07-03 16:57:39
合計ジャッジ時間 8,191 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 92 ms
13,056 KB
testcase_03 AC 117 ms
21,840 KB
testcase_04 AC 118 ms
20,860 KB
testcase_05 AC 90 ms
20,620 KB
testcase_06 AC 90 ms
20,352 KB
testcase_07 AC 28 ms
8,320 KB
testcase_08 AC 100 ms
21,696 KB
testcase_09 AC 10 ms
6,944 KB
testcase_10 AC 45 ms
11,648 KB
testcase_11 AC 32 ms
9,088 KB
testcase_12 AC 20 ms
7,296 KB
testcase_13 AC 95 ms
14,044 KB
testcase_14 AC 110 ms
15,836 KB
testcase_15 AC 127 ms
17,800 KB
testcase_16 AC 58 ms
10,964 KB
testcase_17 AC 142 ms
18,932 KB
testcase_18 AC 40 ms
8,788 KB
testcase_19 AC 132 ms
17,908 KB
testcase_20 AC 31 ms
7,732 KB
testcase_21 AC 48 ms
10,112 KB
testcase_22 AC 122 ms
16,608 KB
testcase_23 AC 3 ms
6,940 KB
testcase_24 AC 3 ms
6,944 KB
testcase_25 AC 18 ms
6,944 KB
testcase_26 AC 66 ms
11,716 KB
testcase_27 AC 68 ms
11,784 KB
testcase_28 AC 126 ms
17,188 KB
testcase_29 AC 14 ms
6,940 KB
testcase_30 AC 133 ms
18,496 KB
testcase_31 AC 91 ms
15,036 KB
testcase_32 AC 58 ms
10,580 KB
testcase_33 AC 138 ms
19,244 KB
testcase_34 AC 50 ms
9,016 KB
testcase_35 AC 138 ms
18,936 KB
testcase_36 AC 2 ms
6,944 KB
testcase_37 AC 3 ms
6,940 KB
testcase_38 AC 3 ms
6,944 KB
testcase_39 AC 3 ms
6,940 KB
testcase_40 AC 2 ms
6,944 KB
testcase_41 AC 222 ms
22,416 KB
testcase_42 AC 50 ms
9,344 KB
testcase_43 AC 102 ms
13,440 KB
testcase_44 AC 30 ms
7,168 KB
testcase_45 AC 97 ms
13,056 KB
testcase_46 AC 2 ms
6,940 KB
testcase_47 AC 2 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <math.h>
#include <deque>
#include <queue>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

template<typename T>
struct Dijkstra{
    const T inf=numeric_limits<T>::max();
    using P=pair<T,int>;
    int n;
    vector<vector<pair<int,T>>> g;
    vector<T> d;
    Dijkstra(int n):n(n),g(n),d(n){}
    void add_edge(int u,int v,T w){
        g[u].emplace_back(v,w);
    }
    vector<T> build(int s){
        for(int i=0;i<n;i++){
            d[i]=inf;
        }
        d[s]=0;
        priority_queue<P,vector<P>,greater<P>> pq;
        pq.emplace(d[s],s);
        while(pq.size()){
            P p=pq.top(); pq.pop();
            int v=p.second;
            if(d[v]<p.first)continue;
            for(auto &e:g[v]){
                int u=e.first; T c=e.second;
                if(d[u]>d[v]+c){
                    d[u]=d[v]+c;
                    pq.emplace(d[u],u);
                }
            }
        }
        return d;
    }
};

double dist(int x,int y,int xx,int yy){
    return sqrt((x-xx)*(x-xx)+(y-yy)*(y-yy));
}

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n,m,x,y; cin >> n >> m >> x >> y;
    x--; y--;
    vector<int> p(n),q(n);
    for(int i=0;i<n;i++){
        cin >> p[i] >> q[i];
    }
    Dijkstra<double> D(n);
    while(m--){
        int a,b; cin >> a >> b;
        a--; b--;
        double d=dist(p[a],q[a],p[b],q[b]);
        D.add_edge(a,b,d);
        D.add_edge(b,a,d);
    }
    printf("%.9f\n",D.build(x)[y]);
}
0