結果

問題 No.1065 電柱 / Pole (Easy)
ユーザー tomatoma
提出日時 2020-05-29 21:44:21
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 364 ms / 2,000 ms
コード長 1,681 bytes
コンパイル時間 1,767 ms
コンパイル使用メモリ 176,388 KB
実行使用メモリ 18,944 KB
最終ジャッジ日時 2024-04-23 21:03:05
合計ジャッジ時間 9,136 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 153 ms
11,264 KB
testcase_03 AC 234 ms
16,920 KB
testcase_04 AC 235 ms
16,920 KB
testcase_05 AC 188 ms
16,796 KB
testcase_06 AC 189 ms
16,920 KB
testcase_07 AC 67 ms
7,552 KB
testcase_08 AC 256 ms
18,944 KB
testcase_09 AC 24 ms
5,376 KB
testcase_10 AC 113 ms
10,240 KB
testcase_11 AC 78 ms
8,320 KB
testcase_12 AC 41 ms
5,376 KB
testcase_13 AC 154 ms
10,892 KB
testcase_14 AC 180 ms
14,168 KB
testcase_15 AC 217 ms
15,500 KB
testcase_16 AC 99 ms
8,132 KB
testcase_17 AC 235 ms
16,100 KB
testcase_18 AC 68 ms
6,528 KB
testcase_19 AC 226 ms
16,436 KB
testcase_20 AC 62 ms
6,656 KB
testcase_21 AC 85 ms
6,784 KB
testcase_22 AC 196 ms
14,684 KB
testcase_23 AC 4 ms
5,376 KB
testcase_24 AC 4 ms
5,376 KB
testcase_25 AC 38 ms
5,376 KB
testcase_26 AC 129 ms
10,340 KB
testcase_27 AC 123 ms
9,352 KB
testcase_28 AC 196 ms
13,472 KB
testcase_29 AC 22 ms
5,376 KB
testcase_30 AC 217 ms
15,812 KB
testcase_31 AC 149 ms
13,412 KB
testcase_32 AC 95 ms
9,472 KB
testcase_33 AC 213 ms
17,672 KB
testcase_34 AC 73 ms
6,912 KB
testcase_35 AC 242 ms
15,636 KB
testcase_36 AC 2 ms
5,376 KB
testcase_37 AC 4 ms
5,376 KB
testcase_38 AC 3 ms
5,376 KB
testcase_39 AC 4 ms
5,376 KB
testcase_40 AC 2 ms
5,376 KB
testcase_41 AC 364 ms
18,688 KB
testcase_42 AC 94 ms
8,192 KB
testcase_43 AC 174 ms
11,520 KB
testcase_44 AC 58 ms
6,528 KB
testcase_45 AC 157 ms
11,264 KB
testcase_46 AC 2 ms
5,376 KB
testcase_47 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include"bits/stdc++.h"
using namespace std;
#define REP(k,m,n) for(int (k)=(m);(k)<(n);(k)++)
#define rep(i,n) REP((i),0,(n))
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using tp3 = tuple<int, int, int>;
using Mat = vector<vector<ll>>;
constexpr int INF = 1 << 28;
constexpr ll INFL = 1ll << 60;
constexpr int dh[4] = { 0,1,0,-1 };
constexpr int dw[4] = { -1,0,1,0 };
bool isin(const int H, const int W, const int h, const int w) {
    return 0 <= h && h < H && 0 <= w && w < W;
}
// ============ template finished ============
using pdd = pair<double, double>;
using pdi = pair<double, int>;
double dist(const vector<pdd>& pq, const int from, const int to) {
    pdd d = { pq[to].first - pq[from].first,pq[to].second - pq[from].second };
    return sqrt(d.first*d.first + d.second*d.second);
}

int main()
{
    int N, M, X, Y;
    cin >> N >> M >> X >> Y;
    X--; Y--;
    vector<pdd> poss(N);
    vector<vector<int>> edges(N);
    rep(i, N)cin >> poss[i].first >> poss[i].second;
    rep(i, M) {
        int P, Q;
        cin >> P >> Q;
        P--; Q--;
        edges[P].push_back(Q);
        edges[Q].push_back(P);
    }
    vector<double> ds(N, INFL);
    priority_queue<pdi, vector<pdi>, greater<pdi>> pq;
    ds[X] = 0;
    pq.push({ 0,X });
    while (!pq.empty()) {
        double d;
        int now;
        tie(d, now) = pq.top(); pq.pop();
        for (auto next : edges[now]) {
            double nd = d + dist(poss, now, next);
            if (nd < ds[next]) {
                ds[next] = nd;
                pq.push({ nd,next });
            }
        }
    }
    cout << fixed << setprecision(12) << ds[Y] << endl;
    return 0;
}
0