結果

問題 No.1065 電柱 / Pole (Easy)
ユーザー kyoprounokyoprouno
提出日時 2020-05-29 21:58:35
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 453 ms / 2,000 ms
コード長 2,229 bytes
コンパイル時間 2,324 ms
コンパイル使用メモリ 188,724 KB
実行使用メモリ 35,712 KB
最終ジャッジ日時 2024-04-23 22:19:48
合計ジャッジ時間 11,598 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
8,452 KB
testcase_01 AC 6 ms
8,436 KB
testcase_02 AC 219 ms
22,016 KB
testcase_03 AC 289 ms
35,672 KB
testcase_04 AC 284 ms
34,828 KB
testcase_05 AC 234 ms
34,468 KB
testcase_06 AC 239 ms
35,712 KB
testcase_07 AC 83 ms
14,888 KB
testcase_08 AC 302 ms
34,068 KB
testcase_09 AC 30 ms
10,376 KB
testcase_10 AC 136 ms
19,720 KB
testcase_11 AC 94 ms
16,104 KB
testcase_12 AC 61 ms
15,352 KB
testcase_13 AC 220 ms
25,352 KB
testcase_14 AC 251 ms
28,204 KB
testcase_15 AC 288 ms
30,708 KB
testcase_16 AC 142 ms
20,956 KB
testcase_17 AC 320 ms
32,816 KB
testcase_18 AC 102 ms
17,772 KB
testcase_19 AC 297 ms
30,992 KB
testcase_20 AC 84 ms
14,536 KB
testcase_21 AC 120 ms
20,832 KB
testcase_22 AC 273 ms
28,740 KB
testcase_23 AC 7 ms
8,808 KB
testcase_24 AC 9 ms
8,900 KB
testcase_25 AC 56 ms
15,196 KB
testcase_26 AC 162 ms
21,196 KB
testcase_27 AC 166 ms
21,960 KB
testcase_28 AC 280 ms
31,092 KB
testcase_29 AC 35 ms
12,524 KB
testcase_30 AC 294 ms
33,232 KB
testcase_31 AC 204 ms
26,576 KB
testcase_32 AC 134 ms
19,012 KB
testcase_33 AC 288 ms
34,552 KB
testcase_34 AC 108 ms
17,656 KB
testcase_35 AC 301 ms
31,988 KB
testcase_36 AC 6 ms
8,500 KB
testcase_37 AC 8 ms
8,768 KB
testcase_38 AC 7 ms
8,668 KB
testcase_39 AC 7 ms
8,752 KB
testcase_40 AC 6 ms
8,656 KB
testcase_41 AC 453 ms
35,544 KB
testcase_42 AC 130 ms
16,484 KB
testcase_43 AC 231 ms
22,740 KB
testcase_44 AC 81 ms
13,464 KB
testcase_45 AC 228 ms
22,232 KB
testcase_46 AC 6 ms
8,356 KB
testcase_47 AC 5 ms
8,480 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
#define pll pair<ll,ll>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))

using namespace std;

template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}

const ll mod=1e9+7;

vector<pair<ll,long double>> to[200005];

const ll INF=1e10+100;
const ll white=0; //未探索
const ll gray=1; //探索中
const ll black=2; //探索済み

ll n,x;
vector<long double> d;

void dijkstra(){
    priority_queue<pll> PQ;
    vector<ll> color(n);
    rep(i,n){
        d[i]=INF;
        color[i]=white;
    }
    d[x]=0;
    PQ.push(make_pair((long double)0.0,x));
    color[x]=gray;
    while(!PQ.empty()){
        pll f=PQ.top();
        PQ.pop();
        ll u=f.second;
        color[u]=black;
        if(d[u]<f.first*(-1)) continue; //d[u]は正。
        for(ll j=0;j<to[u].size();j++){
            ll v=to[u][j].first;
            if(color[v]==black) continue;
            if(d[v]>d[u]+to[u][j].second){
                d[v]=d[u]+to[u][j].second;
                PQ.push(make_pair(d[v]*(-1),v));
                color[v]=gray;
            }
        }
    }
    /*rep(i,n){
        if(d[i]==INF){
            cout << "INF" << endl;
        }
        else{
            cout << d[i] << endl;
        }
    }*/
}

int main()
{
    ll m;
    cin >> n >> m;
    ll y;
    cin >> x >> y;
    x--; y--;
    d.resize(n);
    vector<pair<long double,long double>> p(n);
    rep(i,n){
        cin >> p[i].fi >> p[i].se;
    }
    rep(i,m){
        ll s,t;
        cin >> s >> t;
        s--; t--;
        ll dx=p[s].fi-p[t].fi;
        ll dy=p[s].se-p[t].se;
        long double dist=sqrt(dx*dx+dy*dy);
        to[s].push_back(make_pair(t,dist));
        to[t].push_back(make_pair(s,dist));
    }
    dijkstra();
    cout << fixed << setprecision(10);
    cout << d[y] << endl;
    return 0;
} 
0