結果

問題 No.1065 電柱 / Pole (Easy)
ユーザー kappybarkappybar
提出日時 2020-05-29 21:40:41
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 306 ms / 2,000 ms
コード長 1,558 bytes
コンパイル時間 1,688 ms
コンパイル使用メモリ 175,388 KB
実行使用メモリ 25,960 KB
最終ジャッジ日時 2024-04-23 20:42:30
合計ジャッジ時間 8,894 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
8,192 KB
testcase_01 AC 3 ms
8,192 KB
testcase_02 AC 150 ms
15,724 KB
testcase_03 AC 241 ms
25,828 KB
testcase_04 AC 241 ms
25,832 KB
testcase_05 AC 202 ms
25,960 KB
testcase_06 AC 195 ms
25,876 KB
testcase_07 AC 69 ms
12,000 KB
testcase_08 AC 261 ms
21,932 KB
testcase_09 AC 24 ms
9,332 KB
testcase_10 AC 113 ms
14,268 KB
testcase_11 AC 84 ms
12,416 KB
testcase_12 AC 65 ms
13,964 KB
testcase_13 AC 171 ms
18,512 KB
testcase_14 AC 187 ms
19,236 KB
testcase_15 AC 220 ms
22,580 KB
testcase_16 AC 114 ms
16,400 KB
testcase_17 AC 251 ms
21,692 KB
testcase_18 AC 88 ms
15,044 KB
testcase_19 AC 230 ms
20,864 KB
testcase_20 AC 60 ms
11,904 KB
testcase_21 AC 104 ms
16,520 KB
testcase_22 AC 198 ms
19,876 KB
testcase_23 AC 6 ms
8,576 KB
testcase_24 AC 6 ms
8,608 KB
testcase_25 AC 53 ms
12,724 KB
testcase_26 AC 120 ms
16,468 KB
testcase_27 AC 127 ms
16,908 KB
testcase_28 AC 205 ms
22,924 KB
testcase_29 AC 32 ms
10,908 KB
testcase_30 AC 209 ms
22,880 KB
testcase_31 AC 144 ms
18,540 KB
testcase_32 AC 96 ms
14,756 KB
testcase_33 AC 203 ms
22,296 KB
testcase_34 AC 84 ms
15,004 KB
testcase_35 AC 223 ms
21,864 KB
testcase_36 AC 5 ms
8,300 KB
testcase_37 AC 6 ms
8,484 KB
testcase_38 AC 5 ms
8,300 KB
testcase_39 AC 6 ms
8,240 KB
testcase_40 AC 4 ms
8,192 KB
testcase_41 AC 306 ms
22,668 KB
testcase_42 AC 94 ms
12,672 KB
testcase_43 AC 157 ms
16,000 KB
testcase_44 AC 58 ms
11,020 KB
testcase_45 AC 157 ms
15,604 KB
testcase_46 AC 4 ms
8,192 KB
testcase_47 AC 4 ms
8,140 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
using ll = long long ;
using P = pair<int,int> ;
using pll = pair<double,long long>;
constexpr int INF = 1e9;
constexpr long long LINF = 1e17;
constexpr int MOD = 1000000007;


int n = 200005;
int m;
vector<vector<pll>> graph(n,vector<pll>());

vector<double>  Dijkstra(int start){
    vector<bool> seen(n,false);
    vector<double> shortest(n,LINF);
    priority_queue<pll,vector<pll>,greater<pll>> pq;
    pq.push(pll(0.0,start));

    while(!pq.empty()){
        double dist = pq.top().first;
        int node = pq.top().second;
        pq.pop();
        if(seen[node]) continue;

        shortest[node] = dist;
        seen[node] = true;

        for(pll next:graph[node]){
            int next_node = next.second;
            double next_cost = next.first;
            if(seen[next_node]) continue;
            pq.push(pll(next_cost + dist,next_node));
        }
    }

    return shortest;
}

int main(){
    cin >> n >> m;
    int x,y;
    cin >> x >> y;
    --x;--y;
    vector<pair<double,double>> pq(n);
    rep(i,n) cin >> pq[i].first >> pq[i].second;

    rep(i,m){
        int p,q;
        cin >> p >> q;
        --p;--q;
        double dis = sqrt((pq[p].first - pq[q].first)*(pq[p].first - pq[q].first) + (pq[p].second-pq[q].second)*(pq[p].second-pq[q].second));
        graph[p].push_back(pll(dis,q));
        graph[q].push_back(pll(dis,p));
    }

    vector<double> ans = Dijkstra(x);

    cout << setprecision(20) << ans[y] << endl;

    return 0;
}
0