結果

問題 No.1065 電柱 / Pole (Easy)
ユーザー けーむけーむ
提出日時 2020-06-30 14:57:27
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 240 ms / 2,000 ms
コード長 2,618 bytes
コンパイル時間 2,005 ms
コンパイル使用メモリ 181,576 KB
実行使用メモリ 23,696 KB
最終ジャッジ日時 2023-10-01 01:20:48
合計ジャッジ時間 10,890 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 107 ms
13,540 KB
testcase_03 AC 123 ms
23,068 KB
testcase_04 AC 124 ms
22,816 KB
testcase_05 AC 92 ms
22,840 KB
testcase_06 AC 91 ms
22,288 KB
testcase_07 AC 29 ms
8,388 KB
testcase_08 AC 105 ms
23,068 KB
testcase_09 AC 11 ms
5,008 KB
testcase_10 AC 48 ms
11,964 KB
testcase_11 AC 33 ms
9,116 KB
testcase_12 AC 21 ms
6,812 KB
testcase_13 AC 103 ms
14,592 KB
testcase_14 AC 119 ms
17,348 KB
testcase_15 AC 142 ms
19,040 KB
testcase_16 AC 64 ms
11,240 KB
testcase_17 AC 158 ms
20,316 KB
testcase_18 AC 43 ms
9,000 KB
testcase_19 AC 146 ms
19,572 KB
testcase_20 AC 33 ms
7,896 KB
testcase_21 AC 52 ms
10,356 KB
testcase_22 AC 134 ms
17,988 KB
testcase_23 AC 2 ms
4,376 KB
testcase_24 AC 3 ms
4,376 KB
testcase_25 AC 19 ms
6,388 KB
testcase_26 AC 74 ms
12,828 KB
testcase_27 AC 72 ms
12,160 KB
testcase_28 AC 137 ms
18,372 KB
testcase_29 AC 14 ms
5,708 KB
testcase_30 AC 147 ms
20,280 KB
testcase_31 AC 100 ms
16,228 KB
testcase_32 AC 61 ms
11,060 KB
testcase_33 AC 143 ms
21,316 KB
testcase_34 AC 46 ms
9,120 KB
testcase_35 AC 145 ms
20,644 KB
testcase_36 AC 2 ms
4,380 KB
testcase_37 AC 3 ms
4,376 KB
testcase_38 AC 3 ms
4,380 KB
testcase_39 AC 3 ms
4,376 KB
testcase_40 AC 2 ms
4,376 KB
testcase_41 AC 240 ms
23,696 KB
testcase_42 AC 54 ms
9,388 KB
testcase_43 AC 112 ms
14,064 KB
testcase_44 AC 31 ms
7,176 KB
testcase_45 AC 110 ms
13,544 KB
testcase_46 AC 2 ms
4,384 KB
testcase_47 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())
#define endl "\n"

template<class T>
struct Dijkstra {
    const T inf = numeric_limits<T>::max() / 2 - 1;
    vector<T> dist;
    vector<int> path;
    
    Dijkstra() {}
    Dijkstra(int n) {
        graph.resize(n);
        dist.resize(n);
        prev.resize(n);
    }
    
    void add_edge(int from, int to, T cost) {
        graph[from].emplace_back(to, cost);
    }
    
    void get_distance(int from) {
        priority_queue<pair<T, int>, vector<pair<T, int>>, greater<pair<T, int>>> pq;
        fill(dist.begin(), dist.end(), inf);
        fill(prev.begin(), prev.end(), -1);
        dist[from] = 0;
        pq.push(make_pair(0, from));
        while(!pq.empty()) {
            pair<T, int> p = pq.top(); pq.pop();
            if (dist[p.second] < p.first) continue;
            for (auto e : graph[p.second]) {
                if (dist[e.first] > (dist[p.second] + e.second)) {
                    dist[e.first] = dist[p.second] + e.second;
                    prev[e.first] = p.second;
                    pq.push(make_pair(dist[e.first], e.first));
                }
            }
        }
    }
    
    void get_path(int to) {
        path = vector<int>(0);
        for (; to != -1; to = prev[to]) {
            path.push_back(to);
        }
        reverse(path.begin(), path.end());
    }
    
private:
    vector<vector<pair<int, T>>> graph;
    vector<T> prev;
};

double get_dist(ll x1, ll y1, ll x2, ll y2) {
    ll dx = x1 - x2;
    ll dy = y1 - y2;
    return sqrt(dx * dx + dy * dy);
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // ifstream in("input.txt");
    // cin.rdbuf(in.rdbuf());
    ll n, m, x, y;
    cin >> n >> m >> x >> y;
    x--; y--;
    vector<pair<ll, ll>> pos(n);
    rep(i, n) {
        ll p, q;
        cin >> p >> q;
        pos[i] = make_pair(p, q);
    }
    Dijkstra<double> di(n);
    rep(i, m) {
        ll p, q;
        cin >> p >> q;
        p--; q--;
        double d = get_dist(pos[p].first, pos[p].second, pos[q].first, pos[q].second);
        di.add_edge(p, q, d);
        di.add_edge(q, p, d);
    }
    di.get_distance(x);
    printf("%.10f\n", di.dist[y]);
    return 0;
}
0