結果

問題 No.1065 電柱 / Pole (Easy)
ユーザー udonmanudonman
提出日時 2020-09-17 10:54:49
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 284 ms / 2,000 ms
コード長 2,538 bytes
コンパイル時間 1,336 ms
コンパイル使用メモリ 130,172 KB
実行使用メモリ 22,496 KB
最終ジャッジ日時 2023-09-04 07:08:24
合計ジャッジ時間 7,535 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 124 ms
13,156 KB
testcase_03 AC 145 ms
21,136 KB
testcase_04 AC 147 ms
21,220 KB
testcase_05 AC 106 ms
22,496 KB
testcase_06 AC 106 ms
21,556 KB
testcase_07 AC 38 ms
8,248 KB
testcase_08 AC 140 ms
21,444 KB
testcase_09 AC 14 ms
4,996 KB
testcase_10 AC 64 ms
11,456 KB
testcase_11 AC 44 ms
8,700 KB
testcase_12 AC 20 ms
6,932 KB
testcase_13 AC 116 ms
14,148 KB
testcase_14 AC 136 ms
16,600 KB
testcase_15 AC 161 ms
18,360 KB
testcase_16 AC 65 ms
11,056 KB
testcase_17 AC 176 ms
19,480 KB
testcase_18 AC 46 ms
8,892 KB
testcase_19 AC 171 ms
18,620 KB
testcase_20 AC 38 ms
7,840 KB
testcase_21 AC 52 ms
10,448 KB
testcase_22 AC 155 ms
17,460 KB
testcase_23 AC 2 ms
4,380 KB
testcase_24 AC 3 ms
4,376 KB
testcase_25 AC 19 ms
6,680 KB
testcase_26 AC 81 ms
12,232 KB
testcase_27 AC 81 ms
12,080 KB
testcase_28 AC 157 ms
17,836 KB
testcase_29 AC 14 ms
5,900 KB
testcase_30 AC 165 ms
19,604 KB
testcase_31 AC 115 ms
15,728 KB
testcase_32 AC 72 ms
10,964 KB
testcase_33 AC 169 ms
20,420 KB
testcase_34 AC 51 ms
9,216 KB
testcase_35 AC 171 ms
19,656 KB
testcase_36 AC 2 ms
4,380 KB
testcase_37 AC 3 ms
4,380 KB
testcase_38 AC 2 ms
4,380 KB
testcase_39 AC 3 ms
4,380 KB
testcase_40 AC 2 ms
4,380 KB
testcase_41 AC 284 ms
22,376 KB
testcase_42 AC 68 ms
8,904 KB
testcase_43 AC 136 ms
13,496 KB
testcase_44 AC 39 ms
7,156 KB
testcase_45 AC 126 ms
12,972 KB
testcase_46 AC 2 ms
4,380 KB
testcase_47 AC 2 ms
4,380 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;
    vector<edge> edges;
    int n;
    Graph(int n)
            :n(n)
    {
        g.resize(n);
    }
    void Add(int from, int to, T cost)
    {
        g[from].push_back({to, cost});
        g[to].push_back({from, cost});
    }
    void Add_Edge(int from, int to)
    {
        edges.push_back({from, to});
    }
};

template<typename T>
vector<T> dijkstra(const 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 expected = pq.top().first;
        int i = pq.top().second;
        pq.pop();
        if (dist[i] != expected)
        {
            continue;
        }
        for (auto e : g.g[i])
        {
            int j = e.to;
            T c = e.cost;
            if (dist[j] > dist[i] + c)
            {
                dist[j] = dist[i] + c;
                pq.push({dist[j], j});
            }
        }
    }
    return dist;
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    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> dist = dijkstra(G, x);
    cout << fixed << setprecision(17) << dist[y] << '\n';
    return 0;
}
0