結果

問題 No.1065 電柱 / Pole (Easy)
ユーザー IKyoproIKyopro
提出日時 2020-05-29 22:18:26
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 186 ms / 2,000 ms
コード長 1,342 bytes
コンパイル時間 2,178 ms
コンパイル使用メモリ 211,772 KB
実行使用メモリ 22,008 KB
最終ジャッジ日時 2024-11-06 05:22:15
合計ジャッジ時間 6,805 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,820 KB
testcase_01 AC 2 ms
6,820 KB
testcase_02 AC 81 ms
12,928 KB
testcase_03 AC 115 ms
22,008 KB
testcase_04 AC 114 ms
20,856 KB
testcase_05 AC 86 ms
20,628 KB
testcase_06 AC 86 ms
21,860 KB
testcase_07 AC 28 ms
8,192 KB
testcase_08 AC 101 ms
20,992 KB
testcase_09 AC 11 ms
6,816 KB
testcase_10 AC 46 ms
11,264 KB
testcase_11 AC 32 ms
8,704 KB
testcase_12 AC 20 ms
7,040 KB
testcase_13 AC 83 ms
14,188 KB
testcase_14 AC 98 ms
16,216 KB
testcase_15 AC 111 ms
17,864 KB
testcase_16 AC 54 ms
11,216 KB
testcase_17 AC 136 ms
19,024 KB
testcase_18 AC 39 ms
9,120 KB
testcase_19 AC 115 ms
18,404 KB
testcase_20 AC 29 ms
7,804 KB
testcase_21 AC 44 ms
10,488 KB
testcase_22 AC 102 ms
17,020 KB
testcase_23 AC 3 ms
6,820 KB
testcase_24 AC 3 ms
6,820 KB
testcase_25 AC 19 ms
6,912 KB
testcase_26 AC 60 ms
11,968 KB
testcase_27 AC 63 ms
11,856 KB
testcase_28 AC 107 ms
17,656 KB
testcase_29 AC 13 ms
6,820 KB
testcase_30 AC 117 ms
19,096 KB
testcase_31 AC 80 ms
15,340 KB
testcase_32 AC 48 ms
10,636 KB
testcase_33 AC 121 ms
21,120 KB
testcase_34 AC 41 ms
9,384 KB
testcase_35 AC 115 ms
19,304 KB
testcase_36 AC 2 ms
6,820 KB
testcase_37 AC 3 ms
6,816 KB
testcase_38 AC 3 ms
6,816 KB
testcase_39 AC 3 ms
6,820 KB
testcase_40 AC 3 ms
6,816 KB
testcase_41 AC 186 ms
21,828 KB
testcase_42 AC 45 ms
9,216 KB
testcase_43 AC 84 ms
13,184 KB
testcase_44 AC 28 ms
7,040 KB
testcase_45 AC 79 ms
12,928 KB
testcase_46 AC 2 ms
6,816 KB
testcase_47 AC 2 ms
6,820 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T, class U> using Pa = pair<T, U>;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N,M;
    cin >> N >> M;
    int S,T;
    cin >> S >> T;
    S--; T--;
    vec<int> P(N),Q(N);
    for(int i=0;i<N;i++) cin >> P[i] >> Q[i];
    
    auto dist = [&](int i,int j){
        double dx = P[i]-P[j],dy = Q[i]-Q[j];
        return sqrt(dx*dx+dy*dy);
    };
    
    vvec<Pa<double,int>> g(N);
    for(int i=0;i<M;i++){
        int a,b;
        cin >> a >> b;
        a--; b--;
        double d = dist(a,b);
        g[a].push_back({d,b});
        g[b].push_back({d,a});
    }
    double inf = 1e9;
    vec<double> D(N,inf);
    vec<int> check(N,0);
    priority_queue<Pa<double,int>,vec<Pa<double,int>>,greater<Pa<double,int>>> que;
    que.push({0.0,S});
    D[S] = 0;
    while(!que.empty()){
        auto [d,cur] = que.top(); que.pop();
        if(check[cur]) continue;
        check[cur] = 1;
        for(auto& e:g[cur]){
            double nd = d+e.first;
            if(D[e.second]>nd){
                D[e.second] = nd;
                que.push({nd,e.second});
            }
        }
    }
    cout << fixed << setprecision(10) << D[T] << "\n";
}
0