結果

問題 No.1065 電柱 / Pole (Easy)
ユーザー wkwk
提出日時 2020-05-29 21:52:08
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 354 ms / 2,000 ms
コード長 1,832 bytes
コンパイル時間 2,082 ms
コンパイル使用メモリ 175,612 KB
実行使用メモリ 22,460 KB
最終ジャッジ日時 2024-04-23 21:45:22
合計ジャッジ時間 9,946 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 149 ms
13,224 KB
testcase_03 AC 234 ms
21,876 KB
testcase_04 AC 220 ms
21,488 KB
testcase_05 AC 188 ms
21,488 KB
testcase_06 AC 189 ms
21,364 KB
testcase_07 AC 66 ms
8,576 KB
testcase_08 AC 244 ms
21,888 KB
testcase_09 AC 21 ms
5,376 KB
testcase_10 AC 108 ms
11,776 KB
testcase_11 AC 74 ms
9,216 KB
testcase_12 AC 48 ms
8,064 KB
testcase_13 AC 154 ms
15,240 KB
testcase_14 AC 185 ms
17,308 KB
testcase_15 AC 213 ms
18,904 KB
testcase_16 AC 101 ms
12,044 KB
testcase_17 AC 237 ms
20,208 KB
testcase_18 AC 74 ms
9,728 KB
testcase_19 AC 226 ms
19,236 KB
testcase_20 AC 56 ms
7,680 KB
testcase_21 AC 88 ms
11,520 KB
testcase_22 AC 188 ms
18,020 KB
testcase_23 AC 3 ms
5,376 KB
testcase_24 AC 4 ms
5,376 KB
testcase_25 AC 41 ms
7,808 KB
testcase_26 AC 109 ms
12,660 KB
testcase_27 AC 107 ms
12,864 KB
testcase_28 AC 199 ms
18,848 KB
testcase_29 AC 25 ms
6,400 KB
testcase_30 AC 206 ms
20,132 KB
testcase_31 AC 141 ms
15,944 KB
testcase_32 AC 93 ms
11,292 KB
testcase_33 AC 204 ms
20,624 KB
testcase_34 AC 76 ms
9,852 KB
testcase_35 AC 224 ms
20,512 KB
testcase_36 AC 4 ms
5,376 KB
testcase_37 AC 4 ms
5,376 KB
testcase_38 AC 3 ms
5,376 KB
testcase_39 AC 4 ms
5,376 KB
testcase_40 AC 2 ms
5,376 KB
testcase_41 AC 354 ms
22,460 KB
testcase_42 AC 89 ms
9,472 KB
testcase_43 AC 166 ms
13,696 KB
testcase_44 AC 56 ms
7,424 KB
testcase_45 AC 160 ms
13,568 KB
testcase_46 AC 2 ms
5,376 KB
testcase_47 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; (i) < (n); (i)++)
using namespace std;

//Dijkstra
struct Edge{
    int to;
    double cost;
    Edge(int t, double c){
        to = t;
        cost = c;
    }
};
typedef pair<double, int> P;//距離、点

struct Dijkstra{
    int V;
    vector<vector<Edge>> G;
    vector<double> d;
    double inf = 1.0e18; // 10^18

    Dijkstra(int vv){
        V = vv;
        G.resize(V);
        d.resize(V);
    }

    void add_data(int a, int b, double c){
        Edge e1(b, c);
        G[a].push_back(e1);
    }

    void calc_dis(int s){
        priority_queue<P, vector<P>, greater<P>> que; //Pのfirstが小さい奴から取り出せる
        REP(i, V) d[i] = inf;
        d[s] = 0.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[e.to] > d[v] + e.cost){
                    d[e.to] = d[v] + e.cost;
                    que.push(P(d[e.to], e.to));
                }
            }
        }
    }
};

int main()
{   
    int N, M; cin >> N >> M;
    int X, Y; cin >> X >> Y;
    int p[200005], q[200005];
    REP(i, N) cin >> p[i] >> q[i];
    int P[200005], Q[200005];
    REP(i, M) cin >> P[i] >> Q[i];

    Dijkstra dk(N);
    REP(i, M){
        double dis = sqrt((double)((p[P[i]-1] - p[Q[i]-1]) * (p[P[i]-1] - p[Q[i]-1]) + (q[P[i]-1] - q[Q[i]-1]) * (q[P[i]-1] - q[Q[i]-1])));
        //cout << dis << endl;
        dk.add_data(P[i]-1, Q[i]-1, dis);
        dk.add_data(Q[i]-1, P[i]-1, dis);
    } 
    dk.calc_dis(X-1);
    //REP(i, N) cout << dk.d[i] << endl;
    cout << fixed;
    cout << setprecision(8) << dk.d[Y-1] << endl;

    return 0;
}

0