結果

問題 No.1065 電柱 / Pole (Easy)
ユーザー granddaifukugranddaifuku
提出日時 2020-06-02 14:15:46
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 241 ms / 2,000 ms
コード長 1,706 bytes
コンパイル時間 1,905 ms
コンパイル使用メモリ 183,312 KB
実行使用メモリ 22,560 KB
最終ジャッジ日時 2024-05-03 01:18:08
合計ジャッジ時間 9,213 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 117 ms
13,056 KB
testcase_03 AC 149 ms
19,988 KB
testcase_04 AC 145 ms
21,080 KB
testcase_05 AC 108 ms
20,396 KB
testcase_06 AC 108 ms
20,436 KB
testcase_07 AC 39 ms
8,320 KB
testcase_08 AC 140 ms
21,760 KB
testcase_09 AC 14 ms
6,944 KB
testcase_10 AC 63 ms
11,520 KB
testcase_11 AC 44 ms
9,088 KB
testcase_12 AC 21 ms
7,168 KB
testcase_13 AC 112 ms
14,060 KB
testcase_14 AC 139 ms
15,964 KB
testcase_15 AC 159 ms
17,904 KB
testcase_16 AC 69 ms
11,008 KB
testcase_17 AC 174 ms
19,108 KB
testcase_18 AC 45 ms
8,832 KB
testcase_19 AC 166 ms
18,356 KB
testcase_20 AC 40 ms
7,552 KB
testcase_21 AC 54 ms
10,240 KB
testcase_22 AC 149 ms
16,656 KB
testcase_23 AC 2 ms
6,944 KB
testcase_24 AC 3 ms
6,940 KB
testcase_25 AC 19 ms
6,940 KB
testcase_26 AC 85 ms
11,720 KB
testcase_27 AC 84 ms
12,004 KB
testcase_28 AC 144 ms
17,468 KB
testcase_29 AC 15 ms
6,940 KB
testcase_30 AC 164 ms
18,236 KB
testcase_31 AC 111 ms
14,392 KB
testcase_32 AC 70 ms
10,452 KB
testcase_33 AC 157 ms
19,108 KB
testcase_34 AC 52 ms
9,088 KB
testcase_35 AC 157 ms
18,552 KB
testcase_36 AC 2 ms
6,940 KB
testcase_37 AC 3 ms
6,944 KB
testcase_38 AC 3 ms
6,944 KB
testcase_39 AC 3 ms
6,944 KB
testcase_40 AC 2 ms
6,940 KB
testcase_41 AC 241 ms
22,560 KB
testcase_42 AC 68 ms
9,216 KB
testcase_43 AC 123 ms
13,568 KB
testcase_44 AC 41 ms
7,040 KB
testcase_45 AC 118 ms
13,312 KB
testcase_46 AC 2 ms
6,940 KB
testcase_47 AC 2 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)n; ++i)
#define FOR(i, a, b) for(int i = a; i < (int)b; ++i)
#define rrep(i, n) for(int i = ((int)n - 1); i >= 0; --i)

using ll = long long;
using ld = long double;

const ll INF = 1e18;
const double Inf = 1e9;
const double EPS = 1e-9;
const int MOD = 1e9 + 7;

int n;
using P = pair<int, int>;

struct edge {
    int to;
    double cost;
};

vector<double> dist;
vector<vector<edge> > g;

void dijkstra(int s) {
    dist = vector<double>(n, Inf);
    dist[s] = 0;
    priority_queue<P, vector<P>, greater<P> > pq;
    pq.push(P(0, s));

    while (!pq.empty()) {
        P p = pq.top();
        pq.pop();
        int v = p.second;
        if (dist[v] < p.first) continue;

        rep (i, g[v].size()) {
            edge e = g[v][i];
            if (dist[e.to] > dist[v] + e.cost) {
                dist[e.to] = dist[v] + e.cost;
                pq.push(P(dist[e.to], e.to));
            }
        }
    }
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(10);
    int m, X, Y;
    cin >> n >> m >> X >> Y;
    g.resize(n);
    vector<pair<double, double> > pole(n);
    rep (i, n) cin >> pole[i].first >> pole[i].second;
    rep (i, m) {
        int p, q;
        cin >> p >> q;
        p--, q--;
        double dx, dy;
        dx = pole[p].first - pole[q].first;
        dy = pole[p].second - pole[q].second;
        double c = sqrt(dx * dx + dy * dy);
        edge e;
        e.cost = c;
        e.to = q;
        g[p].push_back(e);
        e.to = p;
        g[q].push_back(e);
    }
    dijkstra(X - 1);
    cout << dist[Y - 1] << endl;
    
    return 0;
}

0