結果

問題 No.1065 電柱 / Pole (Easy)
ユーザー TAISA_TAISA_
提出日時 2020-05-29 21:32:42
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 196 ms / 2,000 ms
コード長 2,742 bytes
コンパイル時間 2,542 ms
コンパイル使用メモリ 206,748 KB
実行使用メモリ 22,528 KB
最終ジャッジ日時 2024-04-23 20:21:37
合計ジャッジ時間 6,975 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 90 ms
13,184 KB
testcase_03 AC 123 ms
21,352 KB
testcase_04 AC 121 ms
21,228 KB
testcase_05 AC 97 ms
21,048 KB
testcase_06 AC 98 ms
21,104 KB
testcase_07 AC 33 ms
8,320 KB
testcase_08 AC 122 ms
21,888 KB
testcase_09 AC 13 ms
5,376 KB
testcase_10 AC 59 ms
11,776 KB
testcase_11 AC 39 ms
9,088 KB
testcase_12 AC 18 ms
7,296 KB
testcase_13 AC 87 ms
14,452 KB
testcase_14 AC 100 ms
16,852 KB
testcase_15 AC 116 ms
18,704 KB
testcase_16 AC 54 ms
11,468 KB
testcase_17 AC 127 ms
19,876 KB
testcase_18 AC 37 ms
9,088 KB
testcase_19 AC 128 ms
19,028 KB
testcase_20 AC 35 ms
7,808 KB
testcase_21 AC 43 ms
10,624 KB
testcase_22 AC 113 ms
17,680 KB
testcase_23 AC 3 ms
5,376 KB
testcase_24 AC 3 ms
5,376 KB
testcase_25 AC 17 ms
7,168 KB
testcase_26 AC 65 ms
12,476 KB
testcase_27 AC 65 ms
12,324 KB
testcase_28 AC 115 ms
18,024 KB
testcase_29 AC 13 ms
6,016 KB
testcase_30 AC 118 ms
19,772 KB
testcase_31 AC 83 ms
15,988 KB
testcase_32 AC 54 ms
11,216 KB
testcase_33 AC 122 ms
20,408 KB
testcase_34 AC 40 ms
9,344 KB
testcase_35 AC 123 ms
19,956 KB
testcase_36 AC 2 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 196 ms
22,528 KB
testcase_42 AC 51 ms
9,344 KB
testcase_43 AC 92 ms
13,568 KB
testcase_44 AC 35 ms
7,296 KB
testcase_45 AC 92 ms
13,312 KB
testcase_46 AC 2 ms
5,376 KB
testcase_47 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define all(vec) vec.begin(), vec.end()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
template <class T>
using V = vector<T>;
template <class T>
inline void chmin(T &a, const T &b) { a = min(a, b); }
template <class T>
inline void chmax(T &a, const T &b) { a = max(a, b); }
template <class T>
inline bool kbit(const T &x, const int &k) { return ((x >> k) & 1LL); }
inline int popcount(const int &n) { return __builtin_popcount(n); }
inline ll popcountll(const ll &n) { return __builtin_popcountll(n); }
template <class T>
void zip(V<T> &v) {
    sort(all(v));
    v.erase(unique(all(v)), v.end());
}
void dump() {
    cerr << '\n';
}
template <class Head, class... Tail>
void dump(Head &&head, Tail &&... tail) {
    cerr << head << (sizeof...(Tail) == 0 ? " " : ", ");
    dump(std::move(tail)...);
}
template <class T>
void print(const vector<T> &v) {
    for (int i = 0; i < v.size(); i++) cout << v[i] << (i + 1 == v.size() ? '\n' : ' ');
}
template <class T>
void read(vector<T> &v) {
    for (int i = 0; i < v.size(); i++) cin >> v[i];
}
constexpr char sp = ' ', newl = '\n';
constexpr int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
constexpr ll INF = (1LL << 30) - 1LL;
constexpr ll MOD = 1e9 + 7;
//@docs Docs/Dijkstra.md
template <class T>
struct Dijkstra {
    int n;
    vector<vector<pair<int, T>>> G;
    Dijkstra(int n) : n(n), G(n) {}
    void addedge(const int &u, const int &v, const T &c) { G[u].emplace_back(v, c); }
    vector<T> dijkstra(const int &st) {
        priority_queue<pair<T, int>, vector<pair<T, int>>, greater<pair<T, int>>> q;
        vector<T> d(n, INF);
        d[st] = 0;
        q.emplace(0, st);
        while (!q.empty()) {
            int v = q.top().second;
            T dd = q.top().first;
            q.pop();
            if (d[v] < dd) continue;
            for (auto &e : G[v]) {
                if (d[e.first] > d[v] + e.second) {
                    d[e.first] = d[v] + e.second;
                    q.emplace(d[e.first], e.first);
                }
            }
        }
        return d;
    }
};
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n, m;
    cin >> n >> m;
    int a, b;
    cin >> a >> b;
    --a;
    --b;
    V<double> x(n), y(n);
    for (int i = 0; i < n; i++) {
        cin >> x[i] >> y[i];
    }
    Dijkstra<double> g(n);
    for (int i = 0; i < m; i++) {
        int u, v;
        cin >> u >> v;
        --u;
        --v;
        double d = sqrt(pow(x[u] - x[v], 2) + pow(y[u] - y[v], 2));
        g.addedge(u, v, d);
        g.addedge(v, u, d);
    }
    cout << fixed << setprecision(15) << g.dijkstra(a)[b] << newl;
}
0