結果

問題 No.1065 電柱 / Pole (Easy)
ユーザー carrot46carrot46
提出日時 2020-05-29 21:40:59
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 420 ms / 2,000 ms
コード長 1,887 bytes
コンパイル時間 2,049 ms
コンパイル使用メモリ 179,580 KB
実行使用メモリ 31,984 KB
最終ジャッジ日時 2024-04-23 20:44:44
合計ジャッジ時間 10,592 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 192 ms
17,536 KB
testcase_03 AC 276 ms
31,984 KB
testcase_04 AC 258 ms
31,732 KB
testcase_05 AC 213 ms
31,608 KB
testcase_06 AC 208 ms
31,476 KB
testcase_07 AC 65 ms
10,368 KB
testcase_08 AC 249 ms
29,568 KB
testcase_09 AC 22 ms
5,888 KB
testcase_10 AC 108 ms
15,232 KB
testcase_11 AC 75 ms
11,264 KB
testcase_12 AC 54 ms
10,752 KB
testcase_13 AC 196 ms
21,256 KB
testcase_14 AC 226 ms
24,740 KB
testcase_15 AC 267 ms
27,048 KB
testcase_16 AC 129 ms
17,156 KB
testcase_17 AC 288 ms
29,224 KB
testcase_18 AC 90 ms
13,560 KB
testcase_19 AC 272 ms
27,380 KB
testcase_20 AC 70 ms
9,904 KB
testcase_21 AC 110 ms
16,424 KB
testcase_22 AC 244 ms
25,840 KB
testcase_23 AC 4 ms
5,376 KB
testcase_24 AC 4 ms
5,376 KB
testcase_25 AC 50 ms
10,496 KB
testcase_26 AC 145 ms
17,904 KB
testcase_27 AC 147 ms
17,992 KB
testcase_28 AC 255 ms
27,512 KB
testcase_29 AC 29 ms
8,192 KB
testcase_30 AC 270 ms
30,124 KB
testcase_31 AC 183 ms
23,372 KB
testcase_32 AC 117 ms
15,640 KB
testcase_33 AC 261 ms
30,436 KB
testcase_34 AC 98 ms
13,296 KB
testcase_35 AC 289 ms
30,016 KB
testcase_36 AC 3 ms
5,376 KB
testcase_37 AC 4 ms
5,376 KB
testcase_38 AC 3 ms
5,376 KB
testcase_39 AC 4 ms
5,376 KB
testcase_40 AC 2 ms
5,376 KB
testcase_41 AC 420 ms
30,920 KB
testcase_42 AC 115 ms
12,032 KB
testcase_43 AC 206 ms
18,048 KB
testcase_44 AC 69 ms
8,832 KB
testcase_45 AC 200 ms
17,664 KB
testcase_46 AC 2 ms
5,376 KB
testcase_47 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()
#define fi first
#define se second
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,Q,K,A,B;
string S;
const ll MOD = 998244353;
//const ll MOD = (1e+9) + 7;
typedef pair<ll, ll> P;
const ll INF = (1LL<<62);

struct edge{
    int to;
    long double cost;
    edge(){}
    edge(int a, long double v){
        to = a;
        cost = v;
    }
};

#define eps 1e-9

template<class T> bool chmin(T &a, const T &b){
    if(a > b) {a = b; return true;}
    else return false;
}
template<class T> bool chmax(T &a, const T &b){
    if(a < b) {a = b; return true;}
    else return false;
}

int main() {
    cin>>N>>M;
    ll s, g;
    cin>>s>>g;
    --s; --g;
    vec p(N), q(N);
    rep(i,N) cin>>p[i]>>q[i];
    vector<vector<edge> > G(N, vector<edge>(0));
    rep(i,M){
        ll u, v;
        cin>>u>>v;
        --u; --v;
        long double d = sqrt((p[u] - p[v]) * (p[u] - p[v]) + (q[u] - q[v]) * (q[u] - q[v]));
        G[u].emplace_back(v, d);
        G[v].emplace_back(u, d);
    }
    vector<long double> dist(N, 1e+100);
    dist[s] = 0;
    typedef pair<long double, ll> PL;
    priority_queue<PL, vector<PL>, greater<> > pque;
    pque.emplace(0, s);
    while(!pque.empty()){
        PL pl = pque.top();
        pque.pop();
        int v = pl.se;
        long double d = pl.fi;
        if(dist[v] + eps < d) continue;
        for(edge e : G[v]){
            if (e.cost < 0.1 && dist[e.to] < d + eps) continue;
            if(chmin(dist[e.to], d + e.cost)) {
                pque.emplace(dist[e.to], e.to);
            }
        }
    }
    cout<<fixed<<setprecision(10)<<dist[g]<<endl;
}
0