結果

問題 No.1065 電柱 / Pole (Easy)
ユーザー realDivineJKrealDivineJK
提出日時 2020-05-30 01:11:26
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 974 ms / 2,000 ms
コード長 1,571 bytes
コンパイル時間 2,259 ms
コンパイル使用メモリ 181,188 KB
実行使用メモリ 33,216 KB
最終ジャッジ日時 2024-04-24 06:11:38
合計ジャッジ時間 18,373 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 406 ms
17,676 KB
testcase_03 AC 485 ms
25,476 KB
testcase_04 AC 500 ms
25,860 KB
testcase_05 AC 377 ms
24,964 KB
testcase_06 AC 371 ms
24,968 KB
testcase_07 AC 113 ms
11,044 KB
testcase_08 AC 502 ms
33,216 KB
testcase_09 AC 35 ms
6,940 KB
testcase_10 AC 201 ms
16,376 KB
testcase_11 AC 134 ms
12,036 KB
testcase_12 AC 57 ms
6,940 KB
testcase_13 AC 380 ms
15,052 KB
testcase_14 AC 463 ms
21,132 KB
testcase_15 AC 550 ms
23,236 KB
testcase_16 AC 205 ms
10,344 KB
testcase_17 AC 579 ms
23,716 KB
testcase_18 AC 142 ms
7,780 KB
testcase_19 AC 547 ms
25,828 KB
testcase_20 AC 120 ms
9,004 KB
testcase_21 AC 170 ms
7,960 KB
testcase_22 AC 492 ms
22,184 KB
testcase_23 AC 4 ms
6,944 KB
testcase_24 AC 5 ms
6,944 KB
testcase_25 AC 50 ms
6,940 KB
testcase_26 AC 271 ms
14,036 KB
testcase_27 AC 261 ms
12,564 KB
testcase_28 AC 510 ms
19,492 KB
testcase_29 AC 39 ms
6,940 KB
testcase_30 AC 551 ms
24,004 KB
testcase_31 AC 345 ms
20,444 KB
testcase_32 AC 214 ms
13,252 KB
testcase_33 AC 561 ms
23,816 KB
testcase_34 AC 156 ms
8,688 KB
testcase_35 AC 539 ms
23,072 KB
testcase_36 AC 3 ms
6,940 KB
testcase_37 AC 6 ms
6,940 KB
testcase_38 AC 5 ms
6,940 KB
testcase_39 AC 6 ms
6,948 KB
testcase_40 AC 2 ms
6,944 KB
testcase_41 AC 974 ms
32,868 KB
testcase_42 AC 224 ms
12,088 KB
testcase_43 AC 447 ms
18,400 KB
testcase_44 AC 124 ms
9,296 KB
testcase_45 AC 425 ms
18,216 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;
double calc_dist(int x1, int y1, int x2, int y2){
    long long tmpx = (x1 - x2) * (x1 - x2);
    long long tmpy = (y1 - y2) * (y1 - y2);
    return sqrt(tmpx + tmpy);
}
int main(void){
    // Your code here!
    int N, M;
    cin >> N >> M;
    int X, Y;
    cin >> X >> Y;
    X--;
    Y--;
    map<int, vector<int>> D;
    vector<pair<int, int>> p(N);
    int x, y;
    for (int i=0;i<N;i++){
        cin >> x >> y;
        p[i] = make_pair(x, y);
    }
    for (int i=0;i<M;i++){
        cin >> x >> y;
        x--;
        y--;
        if (D.count(x)){
            D[x].push_back(y);
        }
        else{
            D[x] = {y};
        }
        if (D.count(y)){
            D[y].push_back(x);
        }
        else{
            D[y] = {x};
        }
    }
    priority_queue<pair<double, int>, vector<pair<double, int>>, greater<pair<double, int>>> pq;
    vector<double> dist(N, 1e9);
    dist[X] = 0.0;
    for (int i=0;i<N;i++){
        pq.push(make_pair(dist[i], i));
    }
    pair<double, int> tmp;
    int r;
    while (!pq.empty()){
        tmp = pq.top();
        pq.pop();
        r = tmp.second;
        if (D.count(r)){
            for (int i: D[r]){
                if (dist[i] > dist[r] + calc_dist(p[i].first, p[i].second, p[r].first, p[r].second)){
                    dist[i] = dist[r] + calc_dist(p[i].first, p[i].second, p[r].first, p[r].second);
                    pq.push(make_pair(dist[i], i));
                }
            }
        }
    }
    printf("%.015f\n", dist[Y]);
    return 0;
}
0