結果

問題 No.1065 電柱 / Pole (Easy)
ユーザー mugen_1337mugen_1337
提出日時 2020-05-29 21:40:08
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 286 ms / 2,000 ms
コード長 1,786 bytes
コンパイル時間 2,471 ms
コンパイル使用メモリ 206,384 KB
実行使用メモリ 23,232 KB
最終ジャッジ日時 2024-04-23 20:41:06
合計ジャッジ時間 8,483 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 124 ms
13,568 KB
testcase_03 AC 150 ms
22,540 KB
testcase_04 AC 148 ms
22,384 KB
testcase_05 AC 113 ms
22,200 KB
testcase_06 AC 110 ms
21,700 KB
testcase_07 AC 38 ms
8,448 KB
testcase_08 AC 139 ms
22,532 KB
testcase_09 AC 14 ms
6,944 KB
testcase_10 AC 62 ms
12,032 KB
testcase_11 AC 43 ms
9,344 KB
testcase_12 AC 21 ms
7,296 KB
testcase_13 AC 113 ms
14,728 KB
testcase_14 AC 133 ms
17,356 KB
testcase_15 AC 155 ms
19,020 KB
testcase_16 AC 68 ms
11,588 KB
testcase_17 AC 182 ms
20,228 KB
testcase_18 AC 46 ms
9,344 KB
testcase_19 AC 167 ms
19,512 KB
testcase_20 AC 41 ms
7,936 KB
testcase_21 AC 52 ms
10,624 KB
testcase_22 AC 152 ms
18,088 KB
testcase_23 AC 3 ms
6,944 KB
testcase_24 AC 3 ms
6,940 KB
testcase_25 AC 19 ms
7,040 KB
testcase_26 AC 86 ms
12,724 KB
testcase_27 AC 88 ms
12,524 KB
testcase_28 AC 154 ms
18,588 KB
testcase_29 AC 14 ms
6,940 KB
testcase_30 AC 163 ms
20,152 KB
testcase_31 AC 112 ms
16,300 KB
testcase_32 AC 70 ms
11,336 KB
testcase_33 AC 167 ms
21,152 KB
testcase_34 AC 53 ms
9,472 KB
testcase_35 AC 161 ms
20,464 KB
testcase_36 AC 3 ms
6,944 KB
testcase_37 AC 3 ms
6,944 KB
testcase_38 AC 3 ms
6,944 KB
testcase_39 AC 3 ms
6,940 KB
testcase_40 AC 2 ms
6,940 KB
testcase_41 AC 286 ms
23,232 KB
testcase_42 AC 67 ms
9,472 KB
testcase_43 AC 129 ms
14,052 KB
testcase_44 AC 40 ms
7,296 KB
testcase_45 AC 121 ms
13,568 KB
testcase_46 AC 2 ms
6,944 KB
testcase_47 AC 2 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define INF 1000000000
#define mod 1000000007
using ll=long long;
const ll LINF=1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
// ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return true;}return false;}

template<typename T>
vector<T> dijkstra(int s,vector<vector<pair<int,T>>> &G){
    const T TINF=numeric_limits<T>::max();
    using P=pair<T,int>;
    int n=G.size();
    vector<T> d(n,TINF);
    vector<int> b(n,-1);//previous point
    priority_queue<P,vector<P>,greater<P>> q;
    d[s]=0;
    q.emplace(d[s],s);
    while(!q.empty()){
        P p=q.top();q.pop();
        int v=p.second;
        if(d[v]<p.first) continue;
        for(auto& e:G[v]){
            int u=e.first;
            T c=e.second;
            if(d[u]>d[v]+c){
                d[u]=d[v]+c;
                b[u]=v;
                q.emplace(d[u],u);
            }
        }
    }
    return d;
}


signed main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    
    cout<<fixed<<setprecision(12);

    int n,m;cin>>n>>m;
    int st,gl;cin>>st>>gl;st--,gl--;

    vector<vector<pair<int,double>>> g(n);

    double x[n],y[n];
    rep(i,n){
        cin>>x[i]>>y[i];
    }

    rep(i,m){
        int u,v;cin>>u>>v;u--,v--;
        g[u].push_back({v,sqrt((x[u]-x[v])*(x[u]-x[v])+(y[u]-y[v])*(y[u]-y[v]))});
        g[v].push_back({u,sqrt((x[u]-x[v])*(x[u]-x[v])+(y[u]-y[v])*(y[u]-y[v]))});
    }

    auto dis=dijkstra(st,g);
    cout<<dis[gl]<<endl;
    return 0;
}
0