結果

問題 No.1065 電柱 / Pole (Easy)
ユーザー Re_code_ARe_code_A
提出日時 2020-05-29 21:53:22
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 419 ms / 2,000 ms
コード長 1,414 bytes
コンパイル時間 1,915 ms
コンパイル使用メモリ 181,332 KB
実行使用メモリ 34,176 KB
最終ジャッジ日時 2024-04-23 21:50:47
合計ジャッジ時間 10,692 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 199 ms
16,640 KB
testcase_03 AC 266 ms
31,512 KB
testcase_04 AC 262 ms
34,176 KB
testcase_05 AC 212 ms
33,016 KB
testcase_06 AC 211 ms
32,072 KB
testcase_07 AC 67 ms
9,984 KB
testcase_08 AC 254 ms
28,004 KB
testcase_09 AC 23 ms
6,944 KB
testcase_10 AC 112 ms
14,336 KB
testcase_11 AC 77 ms
11,008 KB
testcase_12 AC 56 ms
10,752 KB
testcase_13 AC 206 ms
20,828 KB
testcase_14 AC 232 ms
25,004 KB
testcase_15 AC 269 ms
26,280 KB
testcase_16 AC 136 ms
16,908 KB
testcase_17 AC 291 ms
28,656 KB
testcase_18 AC 93 ms
13,532 KB
testcase_19 AC 274 ms
27,168 KB
testcase_20 AC 70 ms
9,764 KB
testcase_21 AC 113 ms
16,304 KB
testcase_22 AC 250 ms
25,908 KB
testcase_23 AC 4 ms
6,944 KB
testcase_24 AC 4 ms
6,944 KB
testcase_25 AC 52 ms
10,368 KB
testcase_26 AC 144 ms
17,396 KB
testcase_27 AC 149 ms
17,576 KB
testcase_28 AC 261 ms
27,088 KB
testcase_29 AC 30 ms
8,064 KB
testcase_30 AC 273 ms
30,088 KB
testcase_31 AC 185 ms
22,784 KB
testcase_32 AC 119 ms
15,180 KB
testcase_33 AC 332 ms
31,052 KB
testcase_34 AC 98 ms
13,072 KB
testcase_35 AC 283 ms
30,316 KB
testcase_36 AC 3 ms
6,940 KB
testcase_37 AC 4 ms
6,944 KB
testcase_38 AC 3 ms
6,944 KB
testcase_39 AC 4 ms
6,940 KB
testcase_40 AC 2 ms
6,940 KB
testcase_41 AC 419 ms
29,368 KB
testcase_42 AC 111 ms
11,520 KB
testcase_43 AC 211 ms
17,280 KB
testcase_44 AC 63 ms
8,704 KB
testcase_45 AC 201 ms
16,900 KB
testcase_46 AC 2 ms
6,944 KB
testcase_47 AC 2 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ld long double
#define al(a) (a).begin(),(a).end()
#define mk make_pair
#define check cout<<"?"<<endl;

ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;

int main(){
    cout<<fixed<<setprecision(20);
    int n,m; cin>>n>>m;
    int x,y; cin>>x>>y;
    x--; y--;
    vector<pp> pos(n);
    vector<vector<pair<int,ld>>> path(n);
    rep(i,n){
        int p,q; cin>>p>>q;
        pos[i]=mk(p,q);
    }
    rep(i,m){
        int p,q; cin>>p>>q;
        p--; q--;
        ld dis=0;
        dis+=(pos[p].first-pos[q].first)*(pos[p].first-pos[q].first);
        dis+=(pos[p].second-pos[q].second)*(pos[p].second-pos[q].second);
        dis=sqrt(dis);
        path[p].push_back(mk(q,dis));
        path[q].push_back(mk(p,dis));
    }
    vector<ld> d(n,inf);
    d[x]=0;
    priority_queue<pair<ld,int>, vector<pair<ld,int>>, greater<pair<ld,int>>> pq;
    pq.push(mk(0.0,x)); //cost,s #
    int s,to;
    ld cost,w;
    while(!(pq.empty())){
        tie(cost,s)=pq.top(); pq.pop();
        if(d[s]!=cost) continue;
        for(auto p:path[s]){
            tie(to,w)=p; //#
            if(d[to]>d[s]+w){
                d[to]=d[s]+w;
                pq.push(mk(d[to],to));
            }
        }
    }
    cout<<d[y]<<endl;
}
0