結果

問題 No.1065 電柱 / Pole (Easy)
ユーザー KKT89KKT89
提出日時 2020-06-20 10:41:00
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 211 ms / 2,000 ms
コード長 1,603 bytes
コンパイル時間 1,091 ms
コンパイル使用メモリ 112,080 KB
実行使用メモリ 22,216 KB
最終ジャッジ日時 2023-09-16 17:01:35
合計ジャッジ時間 6,628 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,384 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 77 ms
12,812 KB
testcase_03 AC 111 ms
21,092 KB
testcase_04 AC 107 ms
20,632 KB
testcase_05 AC 85 ms
21,220 KB
testcase_06 AC 84 ms
21,252 KB
testcase_07 AC 27 ms
8,184 KB
testcase_08 AC 97 ms
21,396 KB
testcase_09 AC 10 ms
4,784 KB
testcase_10 AC 43 ms
11,160 KB
testcase_11 AC 30 ms
8,588 KB
testcase_12 AC 19 ms
6,760 KB
testcase_13 AC 85 ms
13,872 KB
testcase_14 AC 100 ms
15,696 KB
testcase_15 AC 108 ms
17,712 KB
testcase_16 AC 53 ms
10,812 KB
testcase_17 AC 124 ms
18,928 KB
testcase_18 AC 38 ms
8,812 KB
testcase_19 AC 119 ms
17,572 KB
testcase_20 AC 29 ms
7,560 KB
testcase_21 AC 46 ms
10,092 KB
testcase_22 AC 112 ms
16,616 KB
testcase_23 AC 2 ms
4,376 KB
testcase_24 AC 3 ms
4,376 KB
testcase_25 AC 17 ms
6,404 KB
testcase_26 AC 58 ms
11,792 KB
testcase_27 AC 60 ms
11,352 KB
testcase_28 AC 111 ms
17,044 KB
testcase_29 AC 13 ms
5,864 KB
testcase_30 AC 116 ms
18,296 KB
testcase_31 AC 80 ms
14,856 KB
testcase_32 AC 49 ms
10,336 KB
testcase_33 AC 119 ms
19,404 KB
testcase_34 AC 40 ms
8,916 KB
testcase_35 AC 113 ms
18,828 KB
testcase_36 AC 3 ms
4,380 KB
testcase_37 AC 3 ms
4,380 KB
testcase_38 AC 2 ms
4,380 KB
testcase_39 AC 3 ms
4,380 KB
testcase_40 AC 2 ms
4,380 KB
testcase_41 AC 211 ms
22,216 KB
testcase_42 AC 52 ms
8,784 KB
testcase_43 AC 99 ms
13,328 KB
testcase_44 AC 30 ms
6,992 KB
testcase_45 AC 94 ms
12,976 KB
testcase_46 AC 2 ms
4,376 KB
testcase_47 AC 1 ms
4,376 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