結果

問題 No.1065 電柱 / Pole (Easy)
ユーザー soto800soto800
提出日時 2020-05-29 22:03:07
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 275 ms / 2,000 ms
コード長 2,285 bytes
コンパイル時間 1,509 ms
コンパイル使用メモリ 171,432 KB
実行使用メモリ 27,196 KB
最終ジャッジ日時 2024-04-23 22:28:20
合計ジャッジ時間 7,973 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
12,228 KB
testcase_01 AC 5 ms
12,736 KB
testcase_02 AC 128 ms
18,912 KB
testcase_03 AC 202 ms
26,844 KB
testcase_04 AC 200 ms
26,988 KB
testcase_05 AC 163 ms
26,996 KB
testcase_06 AC 164 ms
27,196 KB
testcase_07 AC 59 ms
15,220 KB
testcase_08 AC 217 ms
24,260 KB
testcase_09 AC 21 ms
13,380 KB
testcase_10 AC 95 ms
17,480 KB
testcase_11 AC 67 ms
15,940 KB
testcase_12 AC 47 ms
16,192 KB
testcase_13 AC 132 ms
20,708 KB
testcase_14 AC 158 ms
22,240 KB
testcase_15 AC 177 ms
23,384 KB
testcase_16 AC 92 ms
19,448 KB
testcase_17 AC 202 ms
24,892 KB
testcase_18 AC 68 ms
17,092 KB
testcase_19 AC 184 ms
23,500 KB
testcase_20 AC 52 ms
15,876 KB
testcase_21 AC 82 ms
18,448 KB
testcase_22 AC 170 ms
23,468 KB
testcase_23 AC 6 ms
12,228 KB
testcase_24 AC 6 ms
12,740 KB
testcase_25 AC 41 ms
16,228 KB
testcase_26 AC 102 ms
19,472 KB
testcase_27 AC 105 ms
20,232 KB
testcase_28 AC 179 ms
23,996 KB
testcase_29 AC 26 ms
14,280 KB
testcase_30 AC 186 ms
24,320 KB
testcase_31 AC 127 ms
21,596 KB
testcase_32 AC 85 ms
17,944 KB
testcase_33 AC 173 ms
26,396 KB
testcase_34 AC 71 ms
17,576 KB
testcase_35 AC 195 ms
25,368 KB
testcase_36 AC 5 ms
12,608 KB
testcase_37 AC 6 ms
12,356 KB
testcase_38 AC 6 ms
12,100 KB
testcase_39 AC 5 ms
12,612 KB
testcase_40 AC 4 ms
12,996 KB
testcase_41 AC 275 ms
24,984 KB
testcase_42 AC 78 ms
16,196 KB
testcase_43 AC 135 ms
18,884 KB
testcase_44 AC 50 ms
14,788 KB
testcase_45 AC 141 ms
18,760 KB
testcase_46 AC 5 ms
12,232 KB
testcase_47 AC 4 ms
13,128 KB
権限があれば一括ダウンロードができます

ソースコード

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