結果

問題 No.1065 電柱 / Pole (Easy)
ユーザー scol_kpscol_kp
提出日時 2020-05-29 22:06:36
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 271 ms / 2,000 ms
コード長 1,986 bytes
コンパイル時間 2,396 ms
コンパイル使用メモリ 215,364 KB
実行使用メモリ 22,916 KB
最終ジャッジ日時 2024-11-06 04:55:28
合計ジャッジ時間 8,086 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,820 KB
testcase_01 AC 2 ms
6,820 KB
testcase_02 AC 115 ms
13,312 KB
testcase_03 AC 145 ms
22,916 KB
testcase_04 AC 144 ms
22,084 KB
testcase_05 AC 108 ms
22,000 KB
testcase_06 AC 108 ms
22,440 KB
testcase_07 AC 38 ms
8,192 KB
testcase_08 AC 139 ms
21,944 KB
testcase_09 AC 14 ms
6,816 KB
testcase_10 AC 63 ms
11,648 KB
testcase_11 AC 43 ms
9,088 KB
testcase_12 AC 20 ms
7,040 KB
testcase_13 AC 115 ms
14,464 KB
testcase_14 AC 135 ms
16,728 KB
testcase_15 AC 159 ms
18,572 KB
testcase_16 AC 68 ms
11,468 KB
testcase_17 AC 177 ms
19,756 KB
testcase_18 AC 46 ms
9,088 KB
testcase_19 AC 168 ms
19,024 KB
testcase_20 AC 40 ms
7,808 KB
testcase_21 AC 54 ms
10,368 KB
testcase_22 AC 151 ms
17,816 KB
testcase_23 AC 3 ms
6,816 KB
testcase_24 AC 3 ms
6,816 KB
testcase_25 AC 18 ms
7,040 KB
testcase_26 AC 87 ms
12,608 KB
testcase_27 AC 85 ms
12,188 KB
testcase_28 AC 152 ms
18,120 KB
testcase_29 AC 14 ms
6,820 KB
testcase_30 AC 162 ms
19,520 KB
testcase_31 AC 114 ms
16,056 KB
testcase_32 AC 71 ms
11,092 KB
testcase_33 AC 160 ms
20,572 KB
testcase_34 AC 51 ms
9,368 KB
testcase_35 AC 163 ms
19,836 KB
testcase_36 AC 2 ms
6,816 KB
testcase_37 AC 4 ms
6,820 KB
testcase_38 AC 3 ms
6,816 KB
testcase_39 AC 3 ms
6,820 KB
testcase_40 AC 2 ms
6,816 KB
testcase_41 AC 271 ms
22,560 KB
testcase_42 AC 67 ms
9,344 KB
testcase_43 AC 134 ms
13,568 KB
testcase_44 AC 39 ms
7,168 KB
testcase_45 AC 123 ms
13,312 KB
testcase_46 AC 2 ms
6,816 KB
testcase_47 AC 2 ms
6,816 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define FASTIO
using namespace std;

using ll = long long;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

constexpr int I_INF = numeric_limits<int>::max();
constexpr ll L_INF = numeric_limits<ll>::max();

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

struct Pos {
    double x, y;
};

double distance(const Pos& a, const Pos& b) {
    double dx = a.x - b.x;
    double dy = a.y - b.y;
    return sqrt(dx * dx + dy * dy);
}

constexpr double D_INF = 1e20;

using Pid = pair<int, double>;
using Pdi = pair<double, int>;
using Graph = vector<vector<Pid>>;

void solve() {
    ll N, M, X, Y;
    cin >> N >> M >> X >> Y;
    --X, --Y;
    vector<Pos> poss(N);
    for (ll i = 0; i < N; i++) {
        cin >> poss[i].x >> poss[i].y;
    }

    Graph g(N);

    for (ll i = 0; i < M; i++) {
        ll a, b;
        cin >> a >> b;
        --a, --b;
        double c = distance(poss[a], poss[b]);
        g[a].emplace_back(b, c);
        g[b].emplace_back(a, c);
    }

    vector<double> dist(N, D_INF);
    dist[X] = 0.0;
    priority_queue<Pdi, vector<Pdi>, greater<Pdi>> q;
    q.emplace(0.0, X);
    while (!q.empty()) {
        auto [cost, idx] = q.top();
        q.pop();
        if (dist[idx] < cost) continue;
        for (const auto& [to, c] : g[idx]) {
            double ncost = cost + c;
            if (ncost >= dist[to]) continue;
            dist[to] = ncost;
            q.emplace(ncost, to);
        }
    }

    cout << setprecision(20) << dist[Y] << "\n";
}

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

int main() {
#ifdef FASTIO
    cin.tie(0), cout.tie(0);
    ios::sync_with_stdio(false);
#endif
#ifdef FILEINPUT
    ifstream ifs("./in_out/input.txt");
    cin.rdbuf(ifs.rdbuf());
#endif
#ifdef FILEOUTPUT
    ofstream ofs("./in_out/output.txt");
    cout.rdbuf(ofs.rdbuf());
#endif
    solve();
    cout << flush;
    return 0;
}
0