結果

問題 No.1065 電柱 / Pole (Easy)
ユーザー siro53
提出日時 2020-05-29 21:48:06
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 446 ms / 2,000 ms
コード長 2,122 bytes
コンパイル時間 3,022 ms
コンパイル使用メモリ 205,964 KB
最終ジャッジ日時 2025-01-10 16:55:06
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 46
権限があれば一括ダウンロードができます

ソースコード

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