結果

問題 No.1065 電柱 / Pole (Easy)
ユーザー udonmanudonman
提出日時 2020-09-17 09:04:56
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 469 ms / 2,000 ms
コード長 2,325 bytes
コンパイル時間 2,820 ms
コンパイル使用メモリ 104,496 KB
実行使用メモリ 83,808 KB
最終ジャッジ日時 2023-09-04 07:04:51
合計ジャッジ時間 15,739 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
52,516 KB
testcase_01 AC 17 ms
52,400 KB
testcase_02 AC 230 ms
68,340 KB
testcase_03 AC 284 ms
82,068 KB
testcase_04 AC 284 ms
81,096 KB
testcase_05 AC 234 ms
81,080 KB
testcase_06 AC 234 ms
80,716 KB
testcase_07 AC 93 ms
60,600 KB
testcase_08 AC 310 ms
83,268 KB
testcase_09 AC 41 ms
54,936 KB
testcase_10 AC 145 ms
65,936 KB
testcase_11 AC 104 ms
61,920 KB
testcase_12 AC 62 ms
59,136 KB
testcase_13 AC 220 ms
70,260 KB
testcase_14 AC 251 ms
73,836 KB
testcase_15 AC 285 ms
76,712 KB
testcase_16 AC 142 ms
64,836 KB
testcase_17 AC 316 ms
78,648 KB
testcase_18 AC 102 ms
61,532 KB
testcase_19 AC 299 ms
77,368 KB
testcase_20 AC 88 ms
59,596 KB
testcase_21 AC 119 ms
63,816 KB
testcase_22 AC 273 ms
75,292 KB
testcase_23 AC 19 ms
52,892 KB
testcase_24 AC 19 ms
52,972 KB
testcase_25 AC 58 ms
58,684 KB
testcase_26 AC 172 ms
67,044 KB
testcase_27 AC 164 ms
66,452 KB
testcase_28 AC 270 ms
75,676 KB
testcase_29 AC 41 ms
56,348 KB
testcase_30 AC 291 ms
78,100 KB
testcase_31 AC 210 ms
71,604 KB
testcase_32 AC 140 ms
64,640 KB
testcase_33 AC 284 ms
78,440 KB
testcase_34 AC 110 ms
62,096 KB
testcase_35 AC 298 ms
78,492 KB
testcase_36 AC 18 ms
52,852 KB
testcase_37 AC 19 ms
52,892 KB
testcase_38 AC 18 ms
52,676 KB
testcase_39 AC 19 ms
52,812 KB
testcase_40 AC 17 ms
52,620 KB
testcase_41 AC 469 ms
83,808 KB
testcase_42 AC 137 ms
62,252 KB
testcase_43 AC 239 ms
69,252 KB
testcase_44 AC 87 ms
58,744 KB
testcase_45 AC 238 ms
68,576 KB
testcase_46 AC 17 ms
52,356 KB
testcase_47 AC 16 ms
52,252 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#include <numeric>
#include <cmath>
#include <iomanip> //cout << fixed << setprecision(15) << << endl;
#include <cassert>
#include <limits>
//#include "atcoder/all"

using namespace std;
//using namespace atcoder;

#define ll long long int
#define pb push_back
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
//#define P pair<int,int>

int mx8[] = {0,0,1,-1,-1,1,-1,1};
int my8[] = {-1,1,0,0,-1,-1,1,1};
int mx4[] = {1,-1,0,0};
int my4[] = {0,0,-1,1};

template<typename T>
class Graph
{
public:
    struct Edge
    {
        int to;
        T cost;
    };
    struct edge
    {
        int from;
        int to;
    };
    vector<vector<Edge>> g;
    int n;
    Graph(int n)
    {
        g.resize(n);
    }

    void Add(int from, int to, T cost)
    {
        g[from].push_back({to,cost});
        g[to].push_back({from,cost});
    }

};

template<typename T>
vector<T> dijkstra(Graph<T> G, int start)
{
    using P = pair<T,int>;
    vector<T> dist(G.n, numeric_limits<T>::max());
    priority_queue<P,vector<P>,greater<P>> pq;
    dist[start] = 0;
    pq.push({dist[start],start});
    while(!pq.empty())
    {
        T COST = pq.top().first;
        int v = pq.top().second;
        pq.pop();

        if(dist[v] < COST)
        {
            continue;
        }
        for(auto e : G.g[v])
        {
            int j = e.to;
            T c = e.cost;
            if(dist[j] > dist[v] + c)
            {
                dist[j] = dist[v] + c;
                pq.push({dist[j],j});
            }
        }
    }
    return dist;
}


int main(){
    int n, m, x, y;
    cin >> n >> m >> x >> y;
    --x; --y;
    vector<double> p(n),q(n);
    rep(i,n) cin >> p[i] >> q[i];

    Graph<double> G(n);
    rep(i,m){
        int P, Q; cin >> P >> Q;
        P--; Q--;
        double Co = sqrt(pow((p[P]-p[Q]),2) + pow((q[P]-q[Q]),2));
        G.Add(P,Q,Co);
    }
    vector<double> ans;
    ans = dijkstra(G,x);
    cout << fixed << setprecision(10) << ans[y] << endl;
}

0