結果

問題 No.1065 電柱 / Pole (Easy)
ユーザー siro53siro53
提出日時 2020-05-29 21:48:06
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 291 ms / 2,000 ms
コード長 2,122 bytes
コンパイル時間 2,037 ms
コンパイル使用メモリ 206,956 KB
実行使用メモリ 34,304 KB
最終ジャッジ日時 2024-04-23 21:14:44
合計ジャッジ時間 7,949 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 121 ms
19,200 KB
testcase_03 AC 185 ms
34,228 KB
testcase_04 AC 168 ms
33,716 KB
testcase_05 AC 125 ms
33,716 KB
testcase_06 AC 126 ms
33,720 KB
testcase_07 AC 42 ms
11,392 KB
testcase_08 AC 150 ms
32,768 KB
testcase_09 AC 15 ms
6,144 KB
testcase_10 AC 67 ms
16,640 KB
testcase_11 AC 48 ms
12,544 KB
testcase_12 AC 26 ms
11,008 KB
testcase_13 AC 119 ms
22,636 KB
testcase_14 AC 158 ms
26,428 KB
testcase_15 AC 191 ms
29,016 KB
testcase_16 AC 91 ms
17,808 KB
testcase_17 AC 216 ms
31,284 KB
testcase_18 AC 53 ms
14,172 KB
testcase_19 AC 191 ms
29,652 KB
testcase_20 AC 42 ms
10,604 KB
testcase_21 AC 64 ms
16,972 KB
testcase_22 AC 174 ms
27,776 KB
testcase_23 AC 3 ms
5,376 KB
testcase_24 AC 3 ms
5,376 KB
testcase_25 AC 24 ms
10,624 KB
testcase_26 AC 90 ms
19,216 KB
testcase_27 AC 93 ms
18,844 KB
testcase_28 AC 181 ms
29,164 KB
testcase_29 AC 17 ms
8,320 KB
testcase_30 AC 193 ms
32,036 KB
testcase_31 AC 121 ms
24,980 KB
testcase_32 AC 74 ms
16,720 KB
testcase_33 AC 182 ms
32,476 KB
testcase_34 AC 58 ms
13,956 KB
testcase_35 AC 187 ms
32,136 KB
testcase_36 AC 3 ms
5,376 KB
testcase_37 AC 3 ms
5,376 KB
testcase_38 AC 3 ms
5,376 KB
testcase_39 AC 3 ms
5,376 KB
testcase_40 AC 2 ms
5,376 KB
testcase_41 AC 291 ms
34,304 KB
testcase_42 AC 65 ms
12,928 KB
testcase_43 AC 123 ms
19,840 KB
testcase_44 AC 40 ms
9,600 KB
testcase_45 AC 124 ms
19,456 KB
testcase_46 AC 2 ms
5,376 KB
testcase_47 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
template <class T> inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T> inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return 1;
    }
    return 0;
}
void print() { cout << "\n"; }
template <class T> void print(const T &x) { cout << x << "\n"; }
template <class T, class... Args> void print(const T &x, const Args &... args) {
    cout << x << " ";
    print(args...);
}
template <class T> void printVector(const vector<T> &v) {
    for(const T &x : v) {
        cout << x << " ";
    }
    cout << "\n";
}
using ll = long long;

#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
const double EPS = 1e-7;
const int INF = 1 << 30;
const ll LLINF = 1LL << 60;
const double PI = acos(-1);
constexpr int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

//-------------------------------------

using ld = long double;
using P = complex<ld>;
using Data = pair<ld, int>;

struct edge {
    int to;
    ld cost;
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    int n, m, X, Y;
    cin >> n >> m >> X >> Y;
    X--;
    Y--;
    vector<P> p(n);
    for(int i = 0; i < n; i++) {
        ld x, y;
        cin >> x >> y;
        p[i] = P(x, y);
    }
    vector<vector<edge>> g(n);
    for(int i = 0; i < m; i++) {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        g[a].emplace_back(edge{b, abs(p[a] - p[b])});
        g[b].emplace_back(edge{a, abs(p[a] - p[b])});
    }
    priority_queue<Data, vector<Data>, greater<Data>> que;
    vector<ld> d(n, LLINF);
    d[X] = 0;
    que.push(Data(0, X));
    while(que.size()) {
        auto [nd, nv] = que.top();
        que.pop();
        if(nd > d[nv]) {
            continue;
        }
        for(const auto &e : g[nv]) {
            if(d[e.to] > nd + e.cost) {
                d[e.to] = nd + e.cost;
                que.push(Data(d[e.to], e.to));
            }
        }
    }
    print(d[Y]);
}
0