結果

問題 No.1065 電柱 / Pole (Easy)
ユーザー hir355hir355
提出日時 2020-05-29 21:47:52
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 268 ms / 2,000 ms
コード長 2,484 bytes
コンパイル時間 2,011 ms
コンパイル使用メモリ 206,972 KB
実行使用メモリ 21,128 KB
最終ジャッジ日時 2024-04-23 21:14:12
合計ジャッジ時間 8,160 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 126 ms
12,288 KB
testcase_03 AC 198 ms
20,224 KB
testcase_04 AC 199 ms
20,108 KB
testcase_05 AC 193 ms
19,996 KB
testcase_06 AC 164 ms
20,288 KB
testcase_07 AC 57 ms
7,936 KB
testcase_08 AC 212 ms
20,320 KB
testcase_09 AC 20 ms
6,940 KB
testcase_10 AC 93 ms
11,008 KB
testcase_11 AC 65 ms
8,704 KB
testcase_12 AC 44 ms
7,168 KB
testcase_13 AC 130 ms
13,864 KB
testcase_14 AC 151 ms
15,932 KB
testcase_15 AC 180 ms
17,516 KB
testcase_16 AC 89 ms
11,048 KB
testcase_17 AC 198 ms
18,648 KB
testcase_18 AC 64 ms
8,832 KB
testcase_19 AC 183 ms
18,008 KB
testcase_20 AC 48 ms
7,424 KB
testcase_21 AC 79 ms
10,496 KB
testcase_22 AC 166 ms
16,696 KB
testcase_23 AC 3 ms
6,940 KB
testcase_24 AC 3 ms
6,944 KB
testcase_25 AC 38 ms
6,944 KB
testcase_26 AC 97 ms
11,816 KB
testcase_27 AC 102 ms
11,760 KB
testcase_28 AC 171 ms
17,288 KB
testcase_29 AC 25 ms
6,940 KB
testcase_30 AC 181 ms
18,732 KB
testcase_31 AC 126 ms
15,052 KB
testcase_32 AC 81 ms
10,600 KB
testcase_33 AC 176 ms
20,756 KB
testcase_34 AC 66 ms
8,960 KB
testcase_35 AC 182 ms
18,888 KB
testcase_36 AC 2 ms
6,940 KB
testcase_37 AC 4 ms
6,940 KB
testcase_38 AC 3 ms
6,940 KB
testcase_39 AC 3 ms
6,944 KB
testcase_40 AC 2 ms
6,944 KB
testcase_41 AC 268 ms
21,128 KB
testcase_42 AC 79 ms
8,960 KB
testcase_43 AC 133 ms
12,672 KB
testcase_44 AC 45 ms
6,944 KB
testcase_45 AC 131 ms
12,544 KB
testcase_46 AC 2 ms
6,940 KB
testcase_47 AC 1 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define INF_LL 100000000000000000LL
#define INF 200000000
#define MOD 1000000007
#define ll long long
#define all(x) x.begin(), x.end()
#define REP(i, a, b) for(int i = a; i < b; i++)
#define rep(i, n) REP(i, 0, n)
// typedef float double;
// typedef priority_queue prique;
typedef pair<double, int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<P> vp;
typedef vector<ll> vl;
typedef vector<vi> matrix;
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};
int sign[2] = {1, -1};
template <class T> bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T> bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return 1;
    }
    return 0;
}

ll modpow(ll a, ll b, ll m) {
    if(b == 0)
        return 1;
    ll t = modpow(a, b / 2, m);
    if(b & 1) {
        return (t * t % m) * a % m;
    } else {
        return t * t % m;
    }
}

// struct edge {
//     int to;
//     ll cost;
//     edge(int t, ll c) { to = t, cost = c; }
// };

struct edge {
    int to;
    double cost;
    edge(int t, double c) { to = t, cost = c; }
};

vector<double> dijkstra(vector<vector<edge>> &g, int start, int n) {
    priority_queue<P, vector<P>, greater<P>> que;
    vector<double> dist(n, INF_LL);
    dist[start] = 0;
    que.push(P(0, start));
    while(!que.empty()) {
        P p = que.top();
        que.pop();
        int v = p.second;
        if(dist[v] < p.first)
            continue;
        rep(i, (int)g[v].size()) {
            edge e = g[v][i];
            if(dist[e.to] > dist[v] + e.cost) {
                dist[e.to] = dist[v] + e.cost;
                que.push(P(dist[e.to], e.to));
            }
        }
    }
    return dist;
}

signed main() {
    int n, m, x, y;
    cin >> n >> m >> x >> y;
    x--;
    y--;
    vector<pair<int, int>> a(n);
    rep(i, n) cin >> a[i].first >> a[i].second;
    vector<vector<edge>> g(n);
    rep(i, m) {
        int p, q;
        cin >> p >> q;
        double t = sqrt((a[p - 1].first - a[q - 1].first) *
                            (a[p - 1].first - a[q - 1].first) +
                        (a[p - 1].second - a[q - 1].second) *
                            (a[p - 1].second - a[q - 1].second));
        g[p - 1].push_back({q - 1, t});
        g[q - 1].push_back({p - 1, t});
    }
    vector<double> dist = dijkstra(g, x, n);
    cout << fixed << setprecision(15) << dist[y] << endl;
    return 0;
}
0