結果

問題 No.1069 電柱 / Pole (Hard)
ユーザー finefine
提出日時 2020-05-30 00:18:05
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 2,232 bytes
コンパイル時間 1,780 ms
コンパイル使用メモリ 179,640 KB
実行使用メモリ 74,972 KB
最終ジャッジ日時 2023-09-30 21:19:40
合計ジャッジ時間 7,421 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 105 ms
22,984 KB
testcase_05 WA -
testcase_06 AC 59 ms
38,356 KB
testcase_07 AC 26 ms
8,344 KB
testcase_08 AC 23 ms
21,012 KB
testcase_09 AC 102 ms
74,240 KB
testcase_10 AC 9 ms
9,040 KB
testcase_11 AC 15 ms
13,256 KB
testcase_12 AC 4 ms
4,484 KB
testcase_13 AC 100 ms
38,748 KB
testcase_14 AC 9 ms
8,380 KB
testcase_15 AC 21 ms
20,784 KB
testcase_16 AC 15 ms
12,104 KB
testcase_17 AC 14 ms
12,952 KB
testcase_18 AC 8 ms
7,876 KB
testcase_19 AC 145 ms
73,532 KB
testcase_20 AC 183 ms
73,592 KB
testcase_21 AC 75 ms
38,268 KB
testcase_22 AC 12 ms
12,840 KB
testcase_23 AC 214 ms
38,400 KB
testcase_24 AC 36 ms
38,500 KB
testcase_25 AC 179 ms
74,032 KB
testcase_26 AC 58 ms
73,772 KB
testcase_27 AC 59 ms
73,616 KB
testcase_28 AC 58 ms
74,000 KB
testcase_29 AC 6 ms
5,588 KB
testcase_30 AC 2 ms
4,376 KB
testcase_31 AC 1 ms
4,376 KB
testcase_32 AC 1 ms
4,376 KB
testcase_33 AC 2 ms
4,376 KB
testcase_34 AC 1 ms
4,376 KB
testcase_35 AC 2 ms
4,380 KB
testcase_36 AC 2 ms
4,380 KB
testcase_37 AC 49 ms
38,640 KB
testcase_38 AC 16 ms
13,204 KB
testcase_39 AC 2 ms
4,380 KB
testcase_40 AC 5 ms
5,452 KB
testcase_41 AC 14 ms
12,344 KB
testcase_42 AC 26 ms
21,292 KB
testcase_43 AC 5 ms
5,592 KB
testcase_44 AC 90 ms
74,972 KB
testcase_45 AC 39 ms
39,528 KB
testcase_46 AC 80 ms
73,236 KB
testcase_47 AC 44 ms
40,140 KB
testcase_48 AC 210 ms
74,172 KB
testcase_49 AC 9 ms
8,000 KB
testcase_50 AC 8 ms
7,964 KB
testcase_51 AC 61 ms
38,524 KB
testcase_52 AC 7 ms
8,516 KB
testcase_53 AC 21 ms
21,248 KB
testcase_54 AC 1 ms
4,376 KB
testcase_55 AC 2 ms
4,376 KB
testcase_56 AC 1 ms
4,376 KB
testcase_57 AC 2 ms
4,380 KB
testcase_58 AC 2 ms
4,380 KB
testcase_59 AC 2 ms
4,376 KB
testcase_60 AC 1 ms
4,380 KB
testcase_61 AC 2 ms
4,376 KB
testcase_62 AC 2 ms
4,380 KB
testcase_63 AC 2 ms
4,380 KB
testcase_64 AC 2 ms
4,380 KB
testcase_65 AC 1 ms
4,376 KB
testcase_66 AC 1 ms
4,376 KB
testcase_67 AC 1 ms
4,380 KB
testcase_68 AC 1 ms
4,380 KB
testcase_69 AC 3 ms
4,376 KB
testcase_70 AC 3 ms
4,380 KB
testcase_71 AC 3 ms
4,380 KB
testcase_72 AC 2 ms
4,380 KB
testcase_73 AC 2 ms
4,376 KB
testcase_74 AC 3 ms
4,376 KB
testcase_75 AC 3 ms
4,376 KB
testcase_76 AC 95 ms
39,196 KB
testcase_77 AC 112 ms
38,768 KB
testcase_78 AC 6 ms
5,460 KB
testcase_79 AC 181 ms
73,800 KB
testcase_80 AC 154 ms
39,160 KB
testcase_81 AC 34 ms
38,332 KB
testcase_82 AC 305 ms
73,600 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

using namespace std;

using ll = double;

constexpr char newl = '\n';

struct State {
    int at;
    ll cost;
    bitset<2000> vis;
    State(int at, ll cost) : at(at), cost(cost) {}
    bool operator>(const State& s) const {
        return cost > s.cost;
    }
};

struct Edge {
    int to;
    ll cost;
    Edge(int to, ll cost) : to(to), cost(cost) {}
};

using Graph = vector< vector<Edge> >; //隣接リスト

const ll INF = 1e15;
//const int NONE = -1;

//sは始点、mincは最短経路のコスト、prevsは最短経路をたどる際の前の頂点
void dijkstra(int s, int t, const Graph& graph, int K){
    const int n = graph.size();

    vector< vector<ll> > minc(n);

    priority_queue<State, vector<State>, greater<State> > pq;
    {
        State hoge(s, 0);
        hoge.vis.set(s);
        pq.push(move(hoge));
    }
    minc[s].push_back(0);

    while(!pq.empty()) {
        State cur = pq.top();
        pq.pop();

        minc[cur.at].push_back(cur.cost);
        if (minc[t].size() >= K) break;
        if (minc[cur.at].size() >= 100) {
            minc[cur.at].pop_back();
            continue;
        }

        for(const Edge& e : graph[cur.at]) {
            if (cur.vis[e.to] || minc[e.to].size() >= 100) continue;

            ll cost = cur.cost + e.cost;
            State nex(cur);
            nex.vis.set(e.to);
            nex.at = e.to;
            nex.cost = cost;

            pq.push(move(nex));
        }
    }

    for (int i = 0; i < K; i++) {
        cout << fixed << setprecision(15) << (i >= minc[t].size() ? -1 : minc[t][i]) << newl;
    }
}

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

    int n, m, K;
    cin >> n >> m >> K;

    int x, y;
    cin >> x >> y;
    --x; --y;

    vector<int> p(n), q(n);
    for (int i = 0; i < n; i++) {
        cin >> p[i] >> q[i];
    }

    Graph g(n);
    for (int i = 0; i < m; i++) {
        int u, v;
        cin >> u >> v;
        --u; --v;

        ll cost = hypot(p[u] - p[v], q[u] - q[v]);
        g[u].emplace_back(v, cost);
        g[v].emplace_back(u, cost);
    }

    dijkstra(x, y, g, K);
    return 0;
}
0