結果
問題 | No.788 トラックの移動 |
ユーザー | Pachicobue |
提出日時 | 2019-02-19 00:27:06 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 549 ms / 2,000 ms |
コード長 | 7,541 bytes |
コンパイル時間 | 2,978 ms |
コンパイル使用メモリ | 216,972 KB |
実行使用メモリ | 35,328 KB |
最終ジャッジ日時 | 2024-05-08 22:59:49 |
合計ジャッジ時間 | 6,499 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 549 ms
35,328 KB |
testcase_01 | AC | 3 ms
5,376 KB |
testcase_02 | AC | 2 ms
5,376 KB |
testcase_03 | AC | 2 ms
5,376 KB |
testcase_04 | AC | 99 ms
11,648 KB |
testcase_05 | AC | 453 ms
35,328 KB |
testcase_06 | AC | 418 ms
35,328 KB |
testcase_07 | AC | 2 ms
5,376 KB |
testcase_08 | AC | 2 ms
5,376 KB |
testcase_09 | AC | 2 ms
5,376 KB |
testcase_10 | AC | 2 ms
5,376 KB |
testcase_11 | AC | 2 ms
5,376 KB |
testcase_12 | AC | 2 ms
5,376 KB |
testcase_13 | AC | 2 ms
5,376 KB |
testcase_14 | AC | 2 ms
5,376 KB |
testcase_15 | AC | 122 ms
35,200 KB |
testcase_16 | AC | 446 ms
35,328 KB |
ソースコード
#include <bits/stdc++.h> //!===========================================================!// //! dP dP dP !// //! 88 88 88 !// //! 88aaaaa88a .d8888b. .d8888b. .d888b88 .d8888b. 88d888b. !// //! 88 88 88ooood8 88' `88 88' `88 88ooood8 88' `88 !// //! 88 88 88. ... 88. .88 88. .88 88. ... 88 !// //! dP dP `88888P' `88888P8 `88888P8 `88888P' dP !// //!===========================================================!// using ld = long double; using ll = long long; std::mt19937 mt{std::random_device{}()}; template <typename F> constexpr F PI() { return 3.1415926535897932385; } template <typename T, std::size_t N> std::ostream& operator<<(std::ostream& os, const std::array<T, N>& v) { os << "["; for (const auto& e : v) { os << e << ","; } return (os << "]" << std::endl); } template <typename T, typename A> std::ostream& operator<<(std::ostream& os, const std::deque<T, A>& v) { os << "["; for (const auto& e : v) { os << e << ","; } return (os << "]" << std::endl); } template <typename K, typename T, typename C, typename A> std::ostream& operator<<(std::ostream& os, const std::multimap<K, T, C, A>& v) { os << "["; for (const auto& e : v) { os << "<" << e.first << ": " << e.second << ">,"; } return (os << "]" << std::endl); } template <typename T, typename C, typename A> std::ostream& operator<<(std::ostream& os, const std::multiset<T, C, A>& v) { os << "["; for (const auto& e : v) { os << e << ","; } return (os << "]" << std::endl); } template <typename K, typename T, typename C, typename A> std::ostream& operator<<(std::ostream& os, const std::map<K, T, C, A>& v) { os << "["; for (const auto& e : v) { os << "<" << e.first << ": " << e.second << ">,"; } return (os << "]" << std::endl); } template <typename T1, typename T2> std::ostream& operator<<(std::ostream& os, const std::pair<T1, T2>& v) { return (os << "<" << v.first << "," << v.second << ">"); } template <typename T, typename C, typename A> std::ostream& operator<<(std::ostream& os, const std::set<T, C, A>& v) { os << "["; for (const auto& e : v) { os << e << ","; } return (os << "]" << std::endl); } template <typename K, typename T, typename H, typename P, typename A> std::ostream& operator<<(std::ostream& os, const std::unordered_multimap<K, T, H, P, A>& v) { os << "["; for (const auto& e : v) { os << "<" << e.first << ": " << e.second << ">,"; } return (os << "]" << std::endl); } template <typename T, typename H, typename P, typename A> std::ostream& operator<<(std::ostream& os, const std::unordered_multiset<T, H, P, A>& v) { os << "["; for (const auto& e : v) { os << e << ","; } return (os << "]" << std::endl); } template <typename K, typename T, typename H, typename P, typename A> std::ostream& operator<<(std::ostream& os, const std::unordered_map<K, T, H, P, A>& v) { os << "["; for (const auto& e : v) { os << "<" << e.first << ": " << e.second << ">,"; } return (os << "]" << std::endl); } template <typename T, typename H, typename P, typename A> std::ostream& operator<<(std::ostream& os, const std::unordered_set<T, H, P, A>& v) { os << "["; for (const auto& e : v) { os << e << ","; } return (os << "]" << std::endl); } template <typename T, typename A> std::ostream& operator<<(std::ostream& os, const std::vector<T, A>& v) { os << "["; for (const auto& e : v) { os << e << ","; } return (os << "]" << std::endl); } #define show(x) std::cerr << #x << " = " << (x) << std::endl //!=======================================================================================!// //! a88888b. dP .88888. dP !// //! d8' `88 88 d8' `88 88 !// //! 88 .d8888b. .d8888b. d8888P 88 88d888b. .d8888b. 88d888b. 88d888b. !// //! 88 88' `88 Y8ooooo. 88 88 YP88 88' `88 88' `88 88' `88 88' `88 !// //! Y8. .88 88. .88 88 88 Y8. .88 88 88. .88 88. .88 88 88 !// //! Y88888P' `88888P' `88888P' dP `88888' dP `88888P8 88Y888P' dP dP !// //! 88 !// //! dP !// //!=======================================================================================!// template <typename T> struct CostGraph { CostGraph(const std::size_t v) : V{v}, edge(v), rev_edge(v) {} struct Edge { Edge(const std::size_t from, const std::size_t to, const T cost) : from{from}, to{to}, cost{cost} {} const std::size_t from, to; const T cost; bool operator<(const Edge& e) const { return cost != e.cost ? cost < e.cost : to < e.to; } }; void addEdge(const std::size_t from, const std::size_t to, const T cost) { edge[from].push_back(Edge{from, to, cost}), rev_edge[to].push_back(Edge(to, from, cost)); } const std::size_t V; std::vector<std::vector<Edge>> edge, rev_edge; }; template <typename T> constexpr T INF() { return std::numeric_limits<T>::max() / 4; } //!==============================================================!// //! 888888ba oo oo dP dP !// //! 88 `8b 88 88 !// //! 88 88 dP dP 88 .dP .d8888b. d8888P 88d888b. .d8888b. !// //! 88 88 88 88 88888" Y8ooooo. 88 88' `88 88' `88 !// //! 88 .8P 88 88 88 `8b. 88 88 88 88. .88 !// //! 8888888P dP 88 dP `YP `88888P' dP dP `88888P8 !// //! 88 !// //! dP !// //!==============================================================!// template <typename T> std::vector<T> Dijkstra(const CostGraph<T>& g, const std::size_t s) { std::vector<T> d(g.V, INF<T>()); using P = std::pair<T, std::size_t>; std::priority_queue<P, std::vector<P>, std::greater<P>> q; d[s] = 0, q.push({0, s}); while (not q.empty()) { const T cost = q.top().first; const std::size_t v = q.top().second; q.pop(); if (d[v] < cost) { continue; } for (const auto& e : g.edge[v]) { if (d[e.to] <= d[v] + e.cost) { continue; } d[e.to] = d[v] + e.cost, q.push({d[e.to], e.to}); } } return d; } int main() { int N, M, L; std::cin >> N >> M >> L, L--; CostGraph<ll> g(N); std::vector<ll> t(N); ll tsum = 0; for (int i = 0; i < N; i++) { std::cin >> t[i], tsum += t[i]; } for (int i = 0, a, b, c; i < M; i++) { std::cin >> a >> b >> c, a--, b--, g.addEdge(a, b, c), g.addEdge(b, a, c); } for (int i = 0; i < N; i++) { if (t[i] == tsum) { return std::cout << 0 << std::endl, 0; } } std::vector<std::vector<ll>> d(N, std::vector<ll>(N)); for (int i = 0; i < N; i++) { d[i] = Dijkstra(g, i); } ll ans = INF<ll>(); for (int i = 0; i < N; i++) { ll sum = 0; for (int j = 0; j < N; j++) { sum += 2 * d[i][j] * t[j]; } for (int j = 0; j < N; j++) { if (t[j] == 0) { continue; } ans = std::min(ans, sum + d[L][j] - d[i][j]); } } std::cout << ans << std::endl; return 0; }