結果
問題 | No.1069 電柱 / Pole (Hard) |
ユーザー | risujiroh |
提出日時 | 2020-05-29 23:38:07 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 3,883 bytes |
コンパイル時間 | 3,403 ms |
コンパイル使用メモリ | 244,168 KB |
実行使用メモリ | 6,824 KB |
最終ジャッジ日時 | 2024-11-06 12:15:48 |
合計ジャッジ時間 | 6,547 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,816 KB |
testcase_01 | AC | 2 ms
6,820 KB |
testcase_02 | AC | 2 ms
6,820 KB |
testcase_03 | AC | 2 ms
6,816 KB |
testcase_04 | AC | 260 ms
6,820 KB |
testcase_05 | WA | - |
testcase_06 | WA | - |
testcase_07 | WA | - |
testcase_08 | WA | - |
testcase_09 | WA | - |
testcase_10 | WA | - |
testcase_11 | AC | 2 ms
6,820 KB |
testcase_12 | AC | 3 ms
6,820 KB |
testcase_13 | AC | 5 ms
6,816 KB |
testcase_14 | AC | 5 ms
6,820 KB |
testcase_15 | WA | - |
testcase_16 | WA | - |
testcase_17 | WA | - |
testcase_18 | WA | - |
testcase_19 | WA | - |
testcase_20 | WA | - |
testcase_21 | AC | 7 ms
6,816 KB |
testcase_22 | AC | 3 ms
6,816 KB |
testcase_23 | AC | 75 ms
6,816 KB |
testcase_24 | AC | 9 ms
6,816 KB |
testcase_25 | AC | 8 ms
6,820 KB |
testcase_26 | AC | 8 ms
6,820 KB |
testcase_27 | AC | 8 ms
6,820 KB |
testcase_28 | AC | 8 ms
6,816 KB |
testcase_29 | AC | 3 ms
6,820 KB |
testcase_30 | AC | 3 ms
6,816 KB |
testcase_31 | AC | 2 ms
6,816 KB |
testcase_32 | WA | - |
testcase_33 | WA | - |
testcase_34 | WA | - |
testcase_35 | AC | 2 ms
6,816 KB |
testcase_36 | WA | - |
testcase_37 | WA | - |
testcase_38 | WA | - |
testcase_39 | WA | - |
testcase_40 | WA | - |
testcase_41 | WA | - |
testcase_42 | WA | - |
testcase_43 | AC | 3 ms
6,820 KB |
testcase_44 | WA | - |
testcase_45 | WA | - |
testcase_46 | WA | - |
testcase_47 | WA | - |
testcase_48 | WA | - |
testcase_49 | WA | - |
testcase_50 | WA | - |
testcase_51 | WA | - |
testcase_52 | AC | 3 ms
6,820 KB |
testcase_53 | WA | - |
testcase_54 | AC | 2 ms
6,820 KB |
testcase_55 | WA | - |
testcase_56 | AC | 2 ms
6,820 KB |
testcase_57 | WA | - |
testcase_58 | AC | 2 ms
6,820 KB |
testcase_59 | WA | - |
testcase_60 | AC | 2 ms
6,816 KB |
testcase_61 | WA | - |
testcase_62 | AC | 2 ms
6,816 KB |
testcase_63 | AC | 2 ms
6,816 KB |
testcase_64 | WA | - |
testcase_65 | AC | 2 ms
6,820 KB |
testcase_66 | AC | 2 ms
6,816 KB |
testcase_67 | AC | 2 ms
6,816 KB |
testcase_68 | WA | - |
testcase_69 | AC | 3 ms
6,816 KB |
testcase_70 | AC | 4 ms
6,820 KB |
testcase_71 | AC | 4 ms
6,816 KB |
testcase_72 | AC | 3 ms
6,820 KB |
testcase_73 | AC | 3 ms
6,816 KB |
testcase_74 | AC | 4 ms
6,816 KB |
testcase_75 | AC | 4 ms
6,820 KB |
testcase_76 | WA | - |
testcase_77 | WA | - |
testcase_78 | WA | - |
testcase_79 | AC | 7 ms
6,820 KB |
testcase_80 | WA | - |
testcase_81 | AC | 6 ms
6,820 KB |
testcase_82 | WA | - |
ソースコード
#include <bits/stdc++.h> using namespace std; #ifdef LOCAL #include "debug.h" #else #define DEBUG(...) #endif template <class T> struct graph { struct edge { int to; T w; operator int() const { return to; } }; template <class It> struct edge_list { const It bg, ed; It begin() const { return bg; } It end() const { return ed; } auto&& operator[](size_t i) const { return bg[i]; } size_t size() const { return ed - bg; } }; vector<pair<int, edge>> pool; vector<int> head; vector<edge> edges; graph(int n) : head(n + 1) {} void add(int from, int to, T w = 1) { pool.push_back({from, {to, w}}); ++head[from]; } void build() { partial_sum(begin(head), end(head), begin(head)); edges.resize(head.back()); while (not empty(pool)) { edges[--head[pool.back().first]] = pool.back().second; pool.pop_back(); } decltype(pool)().swap(pool); } edge_list<class vector<edge>::const_iterator> operator[](int v) const { return {begin(edges) + head[v], begin(edges) + head[v + 1]}; } edge_list<class vector<edge>::iterator> operator[](int v) { return {begin(edges) + head[v], begin(edges) + head[v + 1]}; } size_t size() const { return std::size(head) - 1; } }; template <class T> constexpr T inf = numeric_limits<T>::max() / 2.1; auto chmin = [](auto&& a, auto b) { return b < a ? a = b, 1 : 0; }; template <class T, class G> auto dijkstra(const G& g, int s, int t) { vector d(size(g), inf<T>); vector prv(size(g), -1); priority_queue<pair<T, int>, vector<pair<T, int>>, greater<>> rh; rh.emplace(d[s] = 0, s); while (not empty(rh)) { auto [dv, v] = rh.top(); rh.pop(); if (dv != d[v]) continue; for (auto&& e : g[v]) if (chmin(d[e.to], dv + e.w)) { rh.emplace(d[e.to], e.to); prv[e.to] = v; } } vector<int> vs; for (int v = t; v != -1; v = prv[v]) { vs.push_back(v); if (v == s) break; } reverse(begin(vs), end(vs)); return make_pair(d[t], vs); } int main() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20); int n, m, k, s, t; cin >> n >> m >> k >> s >> t; --s, --t; vector<double> x(n), y(n); for (int i = 0; i < n; ++i) { cin >> x[i] >> y[i]; } graph<double> g(n); while (m--) { int u, v; cin >> u >> v; --u, --v; double w = hypot(x[v] - x[u], y[v] - y[u]); g.add(u, v, w); g.add(v, u, w); } g.build(); set<pair<double, vector<int>>> se; se.insert(dijkstra<double>(g, s, t)); vector<vector<int>> ps; while (k--) { if (empty(se)) { cout << "-1\n"; continue; } cout << begin(se)->first << '\n'; auto vs = begin(se)->second; ps.push_back(vs); se.erase(begin(se)); double cur = 0; for (int i = 0; i < (int)size(vs) - 1; ++i) { int v = vs[i]; vector<map<int, double>> mp(n); for (auto&& p : ps) { if (i < (int)size(p) and vector(begin(p), begin(p) + (i + 1)) == vector(begin(vs), begin(vs) + (i + 1))) { for (auto&& e : g[v]) { if (e == p[i + 1]) { mp[v][e] = exchange(e.w, inf<double>); } } } } for (int j = 0; j < i; ++j) { for (auto&& e : g[vs[j]]) { mp[vs[j]][e] = exchange(e.w, inf<double>); } } auto p = dijkstra<double>(g, v, t); if (p.first < inf<double>) { vector nvs(begin(vs), begin(vs) + i); nvs.insert(end(nvs), begin(p.second), end(p.second)); se.emplace(cur + p.first, nvs); } for (int j = 0; j < i; ++j) { for (auto&& e : g[vs[j]]) { e.w = mp[vs[j]][e]; } } for (auto&& e : g[v]) { if (mp[v].count(e)) { e.w = mp[v][e]; } if (e == vs[i + 1]) { cur += e.w; } } } } }