結果

問題 No.1065 電柱 / Pole (Easy)
ユーザー ktr216ktr216
提出日時 2020-05-29 21:47:08
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 368 ms / 2,000 ms
コード長 1,317 bytes
コンパイル時間 1,808 ms
コンパイル使用メモリ 178,208 KB
実行使用メモリ 23,528 KB
最終ジャッジ日時 2024-11-06 03:32:24
合計ジャッジ時間 9,798 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 46
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;

typedef long long ll;

typedef pair<ll, ll> P;
struct edge { ll to; double cost; };

const int MAX_V =200000;
const ll INF = 1LL<<60;

int V;
vector<edge> G[MAX_V];
double d[MAX_V];

void dijkstra(ll s) {
    // greater<P>を指定することでfirstが小さい順に取り出せるようにする
    priority_queue<P, vector<P>, greater<P> > que;
    fill(d, d + V, INF);
    d[s] = 0;
    que.push(P(0, s));

    while (!que.empty()) {
        P p = que.top(); que.pop();
        int v = p.second;
        if (d[v] < p.first) continue;
        rep(i,G[v].size()) {
            edge e = G[v][i];
            if (d[e.to] > d[v] + e.cost) {
                d[e.to] = d[v] + e.cost;
                que.push(P(d[e.to], e.to));
            }
        }
    }
}

int main() {
    int M, X, Y, P, Q;
    cin >> V >> M >> X >> Y;
    vector<int> p(V), q(V);
    rep(i, V) cin >> p[i] >> q[i];
    rep(i, M) {
        cin >> P >> Q;
        P--;
        Q--;
        double dx = p[P] - p[Q];
        double dy = q[P] - q[Q];
        double dist = sqrt(dx * dx + dy * dy);
        G[P].push_back({Q, dist});
        G[Q].push_back({P, dist});
    }
    dijkstra(X - 1);
    cout << fixed << setprecision(20) << d[Y - 1] << "\n";
}
0