結果

問題 No.1065 電柱 / Pole (Easy)
ユーザー milanis48663220milanis48663220
提出日時 2020-05-29 21:39:05
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 191 ms / 2,000 ms
コード長 1,484 bytes
コンパイル時間 884 ms
コンパイル使用メモリ 100,840 KB
実行使用メモリ 22,924 KB
最終ジャッジ日時 2024-04-23 20:37:29
合計ジャッジ時間 5,619 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
8,704 KB
testcase_01 AC 3 ms
8,576 KB
testcase_02 AC 91 ms
15,800 KB
testcase_03 AC 122 ms
22,924 KB
testcase_04 AC 119 ms
22,660 KB
testcase_05 AC 98 ms
22,664 KB
testcase_06 AC 99 ms
22,660 KB
testcase_07 AC 35 ms
12,032 KB
testcase_08 AC 124 ms
22,272 KB
testcase_09 AC 14 ms
9,600 KB
testcase_10 AC 55 ms
14,720 KB
testcase_11 AC 39 ms
12,672 KB
testcase_12 AC 21 ms
12,032 KB
testcase_13 AC 84 ms
17,760 KB
testcase_14 AC 104 ms
19,248 KB
testcase_15 AC 123 ms
20,548 KB
testcase_16 AC 56 ms
15,420 KB
testcase_17 AC 128 ms
21,572 KB
testcase_18 AC 40 ms
13,312 KB
testcase_19 AC 123 ms
20,744 KB
testcase_20 AC 36 ms
11,736 KB
testcase_21 AC 45 ms
14,904 KB
testcase_22 AC 109 ms
19,884 KB
testcase_23 AC 5 ms
8,704 KB
testcase_24 AC 5 ms
8,704 KB
testcase_25 AC 20 ms
11,648 KB
testcase_26 AC 66 ms
15,636 KB
testcase_27 AC 65 ms
15,768 KB
testcase_28 AC 114 ms
20,764 KB
testcase_29 AC 16 ms
10,624 KB
testcase_30 AC 120 ms
21,512 KB
testcase_31 AC 89 ms
18,568 KB
testcase_32 AC 56 ms
14,524 KB
testcase_33 AC 129 ms
22,176 KB
testcase_34 AC 46 ms
13,312 KB
testcase_35 AC 122 ms
22,024 KB
testcase_36 AC 5 ms
8,576 KB
testcase_37 AC 6 ms
8,832 KB
testcase_38 AC 5 ms
8,576 KB
testcase_39 AC 5 ms
8,832 KB
testcase_40 AC 5 ms
8,448 KB
testcase_41 AC 191 ms
22,912 KB
testcase_42 AC 53 ms
13,056 KB
testcase_43 AC 94 ms
16,128 KB
testcase_44 AC 35 ms
11,264 KB
testcase_45 AC 86 ms
16,128 KB
testcase_46 AC 5 ms
8,448 KB
testcase_47 AC 4 ms
8,576 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cmath>

using namespace std;
typedef long long ll;

const double INF = 1e+15;

typedef pair<double, int> P;

struct edge{
    int to;
    double cost;
};

double d[200000];

void dijkstra(int s, int num_v, vector<edge> G[]){
    priority_queue<P, vector<P>, greater<P>> que;
    fill(d, d+num_v, INF);
    d[s] = 0;
    que.push(P(0, s));
    while(!que.empty()){
        P p = que.top();que.pop();
        int v = p.second;
        if(d[v] < p.first) continue;
        for(int i = 0; i < G[v].size(); i++){
            edge e = G[v][i];
            if(d[v] + e.cost < d[e.to]){
                d[e.to] = d[v] + e.cost;
                que.push(P(d[e.to], e.to));
            }
        }
    }
}

double dist(double xa, double xb, double ya, double yb){
    return sqrt((xa-xb)*(xa-xb)+(ya-yb)*(ya-yb));
}

vector<edge> G[200000];
int N, M, X, Y;
double p[200000], q[200000];

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    cin >> N >> M >> X >> Y;
    X--; Y--;
    for(int i = 0; i < N; i++) cin >> p[i] >> q[i];
    for(int i = 0; i < M; i++){
        int P, Q;
        cin >> P >> Q;
        P--; Q--;
        G[P].push_back((edge){Q, dist(p[P], p[Q], q[P], q[Q])});
        G[Q].push_back((edge){P, dist(p[P], p[Q], q[P], q[Q])});
    }
    dijkstra(X, N, G);
    cout << d[Y] << endl;
}
0