結果

問題 No.1065 電柱 / Pole (Easy)
ユーザー outlineoutline
提出日時 2020-12-14 07:45:18
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 269 ms / 2,000 ms
コード長 1,980 bytes
コンパイル時間 1,535 ms
コンパイル使用メモリ 146,180 KB
実行使用メモリ 22,420 KB
最終ジャッジ日時 2023-10-20 04:45:50
合計ジャッジ時間 10,709 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 122 ms
13,124 KB
testcase_03 AC 150 ms
22,420 KB
testcase_04 AC 147 ms
22,420 KB
testcase_05 AC 111 ms
22,420 KB
testcase_06 AC 108 ms
22,420 KB
testcase_07 AC 38 ms
8,388 KB
testcase_08 AC 143 ms
21,892 KB
testcase_09 AC 14 ms
4,964 KB
testcase_10 AC 64 ms
11,540 KB
testcase_11 AC 44 ms
8,916 KB
testcase_12 AC 23 ms
7,360 KB
testcase_13 AC 111 ms
15,236 KB
testcase_14 AC 129 ms
18,404 KB
testcase_15 AC 152 ms
19,460 KB
testcase_16 AC 65 ms
11,360 KB
testcase_17 AC 174 ms
20,780 KB
testcase_18 AC 46 ms
9,452 KB
testcase_19 AC 163 ms
19,988 KB
testcase_20 AC 40 ms
7,860 KB
testcase_21 AC 55 ms
10,604 KB
testcase_22 AC 154 ms
19,460 KB
testcase_23 AC 3 ms
4,348 KB
testcase_24 AC 3 ms
4,348 KB
testcase_25 AC 20 ms
6,740 KB
testcase_26 AC 76 ms
12,612 KB
testcase_27 AC 81 ms
12,876 KB
testcase_28 AC 143 ms
19,460 KB
testcase_29 AC 14 ms
6,092 KB
testcase_30 AC 160 ms
20,252 KB
testcase_31 AC 108 ms
16,028 KB
testcase_32 AC 71 ms
11,556 KB
testcase_33 AC 163 ms
21,572 KB
testcase_34 AC 52 ms
9,452 KB
testcase_35 AC 165 ms
20,516 KB
testcase_36 AC 2 ms
4,348 KB
testcase_37 AC 3 ms
4,348 KB
testcase_38 AC 2 ms
4,348 KB
testcase_39 AC 3 ms
4,348 KB
testcase_40 AC 2 ms
4,348 KB
testcase_41 AC 269 ms
22,420 KB
testcase_42 AC 64 ms
9,180 KB
testcase_43 AC 129 ms
13,652 KB
testcase_44 AC 39 ms
7,068 KB
testcase_45 AC 125 ms
13,388 KB
testcase_46 AC 1 ms
4,348 KB
testcase_47 AC 3 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <array>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <fstream>
#include <complex>
#include <cstring>
#include <unordered_map>
using namespace std;

using ll = long long;
using P = pair<int, int>;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

template<class T>
inline bool chmax(T& x, T y){
    if(x < y){
        x = y;
        return true;
    }
    return false;
}
template<class T>
inline bool chmin(T& x, T y){
    if(x > y){
        x = y;
        return true;
    }
    return false;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int N, M, S, T;
    cin >> N >> M >> S >> T;
    --S, --T;
    vector<complex<double>> ps;
    for(int i = 0; i < N; ++i){
        double x, y;
        cin >> x >> y;
        ps.emplace_back(x, y);
    }
    vector<vector<pair<int, double>>> graph(N);
    for(int i = 0; i < M; ++i){
        int u, v;
        cin >> u >> v;
        --u, --v;
        double d = abs(ps[u] - ps[v]);
        graph[u].emplace_back(v, d);
        graph[v].emplace_back(u, d);
    }

    vector<double> dist(N, 1e+30);
    using Data = pair<double, int>;
    priority_queue<Data, vector<Data>, greater<Data>> que;
    dist[S] = 0.0;
    que.emplace(0, S);
    while(!que.empty()){
        auto [d, from] = que.top();
        que.pop();
        if(dist[from] > d)  continue;
        for(auto [to, cost] : graph[from]){
            if(chmin(dist[to], dist[from] + cost)){
                que.emplace(dist[to], to);
            }
        }
    }

    cout << fixed << setprecision(15);
    cout << dist[T] << endl;

    return 0;
}
0