結果

問題 No.1065 電柱 / Pole (Easy)
ユーザー scol_kpscol_kp
提出日時 2020-05-29 22:06:36
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 194 ms / 2,000 ms
コード長 1,986 bytes
コンパイル時間 2,230 ms
コンパイル使用メモリ 207,756 KB
実行使用メモリ 22,596 KB
最終ジャッジ日時 2024-04-23 22:39:09
合計ジャッジ時間 7,149 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 85 ms
13,312 KB
testcase_03 AC 118 ms
21,652 KB
testcase_04 AC 125 ms
21,268 KB
testcase_05 AC 99 ms
22,104 KB
testcase_06 AC 96 ms
22,084 KB
testcase_07 AC 34 ms
8,320 KB
testcase_08 AC 124 ms
21,980 KB
testcase_09 AC 12 ms
6,940 KB
testcase_10 AC 55 ms
11,648 KB
testcase_11 AC 38 ms
9,216 KB
testcase_12 AC 18 ms
7,168 KB
testcase_13 AC 89 ms
14,460 KB
testcase_14 AC 105 ms
16,852 KB
testcase_15 AC 121 ms
18,568 KB
testcase_16 AC 56 ms
11,468 KB
testcase_17 AC 132 ms
19,752 KB
testcase_18 AC 38 ms
9,088 KB
testcase_19 AC 123 ms
19,024 KB
testcase_20 AC 33 ms
7,936 KB
testcase_21 AC 43 ms
10,496 KB
testcase_22 AC 119 ms
17,676 KB
testcase_23 AC 2 ms
6,940 KB
testcase_24 AC 3 ms
6,940 KB
testcase_25 AC 17 ms
7,168 KB
testcase_26 AC 65 ms
12,476 KB
testcase_27 AC 66 ms
12,320 KB
testcase_28 AC 116 ms
18,124 KB
testcase_29 AC 13 ms
6,944 KB
testcase_30 AC 123 ms
19,648 KB
testcase_31 AC 82 ms
15,920 KB
testcase_32 AC 53 ms
11,208 KB
testcase_33 AC 125 ms
21,844 KB
testcase_34 AC 42 ms
9,468 KB
testcase_35 AC 127 ms
19,956 KB
testcase_36 AC 2 ms
6,944 KB
testcase_37 AC 3 ms
6,940 KB
testcase_38 AC 2 ms
6,944 KB
testcase_39 AC 2 ms
6,944 KB
testcase_40 AC 2 ms
6,940 KB
testcase_41 AC 194 ms
22,596 KB
testcase_42 AC 51 ms
9,472 KB
testcase_43 AC 94 ms
13,568 KB
testcase_44 AC 31 ms
7,168 KB
testcase_45 AC 90 ms
13,312 KB
testcase_46 AC 2 ms
6,940 KB
testcase_47 AC 1 ms
6,944 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