結果

問題 No.1065 電柱 / Pole (Easy)
ユーザー rniyarniya
提出日時 2020-05-30 16:24:27
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 288 ms / 2,000 ms
コード長 1,426 bytes
コンパイル時間 2,426 ms
コンパイル使用メモリ 174,972 KB
実行使用メモリ 24,064 KB
最終ジャッジ日時 2024-04-25 08:52:17
合計ジャッジ時間 8,444 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 129 ms
13,952 KB
testcase_03 AC 151 ms
21,380 KB
testcase_04 AC 149 ms
21,256 KB
testcase_05 AC 114 ms
21,124 KB
testcase_06 AC 111 ms
21,128 KB
testcase_07 AC 39 ms
8,832 KB
testcase_08 AC 142 ms
23,424 KB
testcase_09 AC 15 ms
5,376 KB
testcase_10 AC 64 ms
12,544 KB
testcase_11 AC 44 ms
9,728 KB
testcase_12 AC 21 ms
7,168 KB
testcase_13 AC 124 ms
14,848 KB
testcase_14 AC 140 ms
16,980 KB
testcase_15 AC 166 ms
18,964 KB
testcase_16 AC 71 ms
11,604 KB
testcase_17 AC 184 ms
20,140 KB
testcase_18 AC 51 ms
9,204 KB
testcase_19 AC 174 ms
19,032 KB
testcase_20 AC 39 ms
8,064 KB
testcase_21 AC 57 ms
10,624 KB
testcase_22 AC 155 ms
17,684 KB
testcase_23 AC 3 ms
5,376 KB
testcase_24 AC 4 ms
5,376 KB
testcase_25 AC 21 ms
7,168 KB
testcase_26 AC 87 ms
12,488 KB
testcase_27 AC 85 ms
12,452 KB
testcase_28 AC 155 ms
18,124 KB
testcase_29 AC 16 ms
6,016 KB
testcase_30 AC 167 ms
19,696 KB
testcase_31 AC 116 ms
15,880 KB
testcase_32 AC 70 ms
11,168 KB
testcase_33 AC 167 ms
20,436 KB
testcase_34 AC 51 ms
9,376 KB
testcase_35 AC 164 ms
19,992 KB
testcase_36 AC 3 ms
5,376 KB
testcase_37 AC 3 ms
5,376 KB
testcase_38 AC 3 ms
5,376 KB
testcase_39 AC 3 ms
5,376 KB
testcase_40 AC 2 ms
5,376 KB
testcase_41 AC 288 ms
24,064 KB
testcase_42 AC 75 ms
9,984 KB
testcase_43 AC 127 ms
14,336 KB
testcase_44 AC 39 ms
7,680 KB
testcase_45 AC 126 ms
14,208 KB
testcase_46 AC 2 ms
5,376 KB
testcase_47 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

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){
        fill(d.begin(),d.end(),inf);
        d[s]=0;
        priority_queue<P,vector<P>,greater<P>> pq;
        pq.emplace(d[s],s);
        while(!pq.empty()){
            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[v]+c<d[u]){
                    d[u]=d[v]+c;
                    pq.emplace(d[u],u);
                }
            }
        }
        return d;
    }
};

const int MAX_N=2e5+10;

int N,M,X,Y;
double p[MAX_N],q[MAX_N];

double dist(int i,int j){
    return sqrt((p[i]-p[j])*(p[i]-p[j])+(q[i]-q[j])*(q[i]-q[j]));
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N >> M >> X >> Y;
    for (int i=0;i<N;++i) cin >> p[i] >> q[i];
    Dijkstra<double> D(N);
    for (int i=0;i<M;++i){
        int P,Q; cin >> P >> Q;
        double d=dist(--P,--Q);
        D.add_edge(P,Q,d);
        D.add_edge(Q,P,d);
    }
    cout << fixed << setprecision(10);
    cout << D.build(--X)[--Y] << '\n';
}
0