結果

問題 No.1065 電柱 / Pole (Easy)
ユーザー IKyoproIKyopro
提出日時 2020-05-29 22:18:26
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 236 ms / 2,000 ms
コード長 1,342 bytes
コンパイル時間 2,370 ms
コンパイル使用メモリ 204,856 KB
実行使用メモリ 21,932 KB
最終ジャッジ日時 2024-04-23 23:03:55
合計ジャッジ時間 7,558 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 103 ms
13,056 KB
testcase_03 AC 123 ms
21,440 KB
testcase_04 AC 120 ms
21,236 KB
testcase_05 AC 90 ms
21,768 KB
testcase_06 AC 91 ms
21,912 KB
testcase_07 AC 29 ms
8,192 KB
testcase_08 AC 104 ms
21,144 KB
testcase_09 AC 11 ms
6,940 KB
testcase_10 AC 47 ms
11,520 KB
testcase_11 AC 33 ms
8,832 KB
testcase_12 AC 22 ms
7,296 KB
testcase_13 AC 107 ms
14,316 KB
testcase_14 AC 117 ms
16,348 KB
testcase_15 AC 137 ms
17,980 KB
testcase_16 AC 65 ms
11,208 KB
testcase_17 AC 155 ms
19,280 KB
testcase_18 AC 44 ms
9,244 KB
testcase_19 AC 143 ms
18,272 KB
testcase_20 AC 32 ms
7,808 KB
testcase_21 AC 51 ms
10,504 KB
testcase_22 AC 132 ms
17,144 KB
testcase_23 AC 3 ms
6,940 KB
testcase_24 AC 3 ms
6,940 KB
testcase_25 AC 20 ms
7,168 KB
testcase_26 AC 73 ms
12,088 KB
testcase_27 AC 76 ms
11,860 KB
testcase_28 AC 137 ms
17,532 KB
testcase_29 AC 14 ms
6,940 KB
testcase_30 AC 141 ms
18,964 KB
testcase_31 AC 96 ms
15,312 KB
testcase_32 AC 60 ms
10,760 KB
testcase_33 AC 135 ms
19,836 KB
testcase_34 AC 45 ms
9,252 KB
testcase_35 AC 142 ms
19,424 KB
testcase_36 AC 3 ms
6,940 KB
testcase_37 AC 3 ms
6,944 KB
testcase_38 AC 3 ms
6,944 KB
testcase_39 AC 3 ms
6,940 KB
testcase_40 AC 2 ms
6,940 KB
testcase_41 AC 236 ms
21,932 KB
testcase_42 AC 55 ms
9,216 KB
testcase_43 AC 101 ms
13,192 KB
testcase_44 AC 32 ms
7,168 KB
testcase_45 AC 99 ms
13,056 KB
testcase_46 AC 2 ms
6,940 KB
testcase_47 AC 2 ms
6,940 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