結果

問題 No.1069 電柱 / Pole (Hard)
ユーザー finefine
提出日時 2020-05-29 23:27:27
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 2,101 bytes
コンパイル時間 2,118 ms
コンパイル使用メモリ 179,180 KB
実行使用メモリ 13,468 KB
最終ジャッジ日時 2024-04-24 05:17:46
合計ジャッジ時間 3,865 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 1 ms
6,940 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 12 ms
6,944 KB
testcase_05 WA -
testcase_06 AC 11 ms
6,944 KB
testcase_07 AC 11 ms
8,856 KB
testcase_08 AC 17 ms
9,584 KB
testcase_09 AC 14 ms
8,728 KB
testcase_10 AC 8 ms
6,940 KB
testcase_11 AC 3 ms
6,944 KB
testcase_12 AC 7 ms
6,940 KB
testcase_13 AC 16 ms
8,176 KB
testcase_14 AC 16 ms
12,460 KB
testcase_15 AC 22 ms
12,632 KB
testcase_16 AC 9 ms
6,944 KB
testcase_17 AC 11 ms
8,112 KB
testcase_18 AC 12 ms
8,280 KB
testcase_19 AC 19 ms
8,300 KB
testcase_20 AC 18 ms
9,664 KB
testcase_21 AC 16 ms
8,232 KB
testcase_22 AC 16 ms
12,548 KB
testcase_23 AC 15 ms
8,132 KB
testcase_24 AC 15 ms
8,080 KB
testcase_25 AC 14 ms
8,080 KB
testcase_26 AC 12 ms
8,852 KB
testcase_27 AC 13 ms
9,232 KB
testcase_28 AC 13 ms
8,340 KB
testcase_29 AC 4 ms
6,940 KB
testcase_30 AC 2 ms
6,944 KB
testcase_31 WA -
testcase_32 AC 1 ms
6,940 KB
testcase_33 AC 1 ms
6,940 KB
testcase_34 AC 2 ms
6,940 KB
testcase_35 AC 2 ms
6,940 KB
testcase_36 AC 2 ms
6,944 KB
testcase_37 AC 8 ms
6,940 KB
testcase_38 AC 7 ms
6,944 KB
testcase_39 AC 2 ms
6,940 KB
testcase_40 AC 6 ms
6,940 KB
testcase_41 AC 12 ms
7,972 KB
testcase_42 AC 7 ms
6,944 KB
testcase_43 AC 4 ms
6,940 KB
testcase_44 AC 15 ms
8,280 KB
testcase_45 AC 18 ms
8,920 KB
testcase_46 AC 15 ms
8,380 KB
testcase_47 AC 14 ms
8,132 KB
testcase_48 AC 15 ms
9,200 KB
testcase_49 AC 11 ms
8,184 KB
testcase_50 AC 5 ms
6,944 KB
testcase_51 AC 14 ms
9,068 KB
testcase_52 AC 5 ms
6,940 KB
testcase_53 AC 11 ms
9,732 KB
testcase_54 AC 1 ms
6,940 KB
testcase_55 AC 2 ms
6,940 KB
testcase_56 AC 1 ms
6,940 KB
testcase_57 AC 2 ms
6,944 KB
testcase_58 AC 2 ms
6,944 KB
testcase_59 AC 2 ms
6,944 KB
testcase_60 AC 2 ms
6,944 KB
testcase_61 AC 2 ms
6,940 KB
testcase_62 AC 2 ms
6,940 KB
testcase_63 AC 1 ms
6,944 KB
testcase_64 AC 2 ms
6,944 KB
testcase_65 AC 2 ms
6,944 KB
testcase_66 AC 2 ms
6,940 KB
testcase_67 AC 2 ms
6,940 KB
testcase_68 AC 2 ms
6,940 KB
testcase_69 AC 2 ms
6,940 KB
testcase_70 AC 3 ms
6,940 KB
testcase_71 AC 3 ms
6,940 KB
testcase_72 AC 2 ms
6,940 KB
testcase_73 AC 2 ms
6,940 KB
testcase_74 AC 3 ms
6,944 KB
testcase_75 AC 2 ms
6,944 KB
testcase_76 AC 14 ms
8,244 KB
testcase_77 AC 13 ms
8,576 KB
testcase_78 AC 3 ms
6,940 KB
testcase_79 AC 19 ms
13,468 KB
testcase_80 AC 13 ms
9,568 KB
testcase_81 AC 19 ms
12,348 KB
testcase_82 AC 19 ms
12,328 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));
    }

    while(!pq.empty()) {
        State cur = pq.top();
        pq.pop();
        if (minc[cur.at].size() >= K) continue;

        minc[cur.at].push_back(cur.cost);

        for(const Edge& e : graph[cur.at]) {
            if (cur.vis[e.to] || minc[e.to].size() >= K) 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