結果

問題 No.1065 電柱 / Pole (Easy)
ユーザー soto800
提出日時 2020-05-29 22:03:07
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 378 ms / 2,000 ms
コード長 2,285 bytes
コンパイル時間 2,268 ms
コンパイル使用メモリ 174,844 KB
実行使用メモリ 26,512 KB
最終ジャッジ日時 2024-11-06 04:43:57
合計ジャッジ時間 9,502 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 46
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)
#define TO_STRING(VariableName) # VariableName
#define LOG(x) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<endl;
#define LOG2(x,y) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<endl;
#define LOG3(x,y,z) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<" "<<TO_STRING(z)<<"="<<z<<endl;
#define LOG4(w,x,y,z) if(DEBUG)cout<<TO_STRING(w)<<"="<<w<<" "<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<" "<<TO_STRING(z)<<"="<<z<<endl;

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

#define MAX_V 300000
struct edge{
    lli to;
    double cost;
};
bool operator< (const edge &l, const edge &r){
    return l.cost < r.cost;
}
bool operator> (const edge &l, const edge &r){
    return l.cost > r.cost;
}
vector<edge> G[MAX_V];
lli N;
vector<double> dijkstra(lli s){
    priority_queue<edge,vector<edge>,greater<edge>> que;
    vector<double> d(N+2,INF);
    //fill(d,d+n+2,INF);
    d[s]=0;
    que.push({s,0});

    while(!que.empty())
    {
        edge p = que.top();
        que.pop();
        lli v = p.to;
        LOG2(p.to,p.cost);
        if(d[v] < p.cost)continue;

        for(lli i=0;i<G[v].size();i++){
            edge e = G[v][i];
            if(d[e.to] > d[v]+e.cost){
                d[e.to] = d[v]+e.cost;
                que.push({e.to,d[e.to]});
            }
        }
    }
    return d;
}

lli x[200100];
lli y[200100];

int main(){

    lli M;
    cin>>N>>M; 

    lli st,en;
    cin>>st>>en;
    st--,en--;

    REP(i,0,N)cin>>x[i]>>y[i];

    REP(i,0,M){
        lli p,q;
        cin>>p>>q;
        p--,q--;
        lli diffX = x[p]-x[q];
        lli diffY = y[p]-y[q];
        double cost = sqrt(diffX*diffX + diffY*diffY);
        LOG3(p,q,cost);
        G[p].push_back({q,cost});
        G[q].push_back({p,cost});
    }

    auto dist = dijkstra(st);
    cout<<setprecision(15);
    cout<<dist[en]<<endl;

    return 0;
}
0