結果

問題 No.1065 電柱 / Pole (Easy)
ユーザー carrot46
提出日時 2020-05-29 21:40:59
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 407 ms / 2,000 ms
コード長 1,887 bytes
コンパイル時間 1,819 ms
コンパイル使用メモリ 183,768 KB
実行使用メモリ 34,960 KB
最終ジャッジ日時 2024-11-06 03:03:34
合計ジャッジ時間 9,963 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 46
権限があれば一括ダウンロードができます

ソースコード

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