結果
問題 | No.807 umg tours |
ユーザー | commy |
提出日時 | 2020-04-29 18:58:22 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 368 ms / 4,000 ms |
コード長 | 2,382 bytes |
コンパイル時間 | 2,095 ms |
コンパイル使用メモリ | 98,284 KB |
実行使用メモリ | 24,108 KB |
最終ジャッジ日時 | 2023-08-15 12:49:00 |
合計ジャッジ時間 | 6,647 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge13 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
4,380 KB |
testcase_01 | AC | 2 ms
4,380 KB |
testcase_02 | AC | 2 ms
4,376 KB |
testcase_03 | AC | 2 ms
4,376 KB |
testcase_04 | AC | 1 ms
4,380 KB |
testcase_05 | AC | 2 ms
4,380 KB |
testcase_06 | AC | 2 ms
4,380 KB |
testcase_07 | AC | 2 ms
4,380 KB |
testcase_08 | AC | 2 ms
4,376 KB |
testcase_09 | AC | 1 ms
4,380 KB |
testcase_10 | AC | 2 ms
4,376 KB |
testcase_11 | AC | 158 ms
15,112 KB |
testcase_12 | AC | 206 ms
13,164 KB |
testcase_13 | AC | 267 ms
16,272 KB |
testcase_14 | AC | 115 ms
8,992 KB |
testcase_15 | AC | 88 ms
7,824 KB |
testcase_16 | AC | 270 ms
17,888 KB |
testcase_17 | AC | 368 ms
22,512 KB |
testcase_18 | AC | 363 ms
22,264 KB |
testcase_19 | AC | 350 ms
19,992 KB |
testcase_20 | AC | 239 ms
12,472 KB |
testcase_21 | AC | 242 ms
12,760 KB |
testcase_22 | AC | 97 ms
7,316 KB |
testcase_23 | AC | 73 ms
6,280 KB |
testcase_24 | AC | 218 ms
20,380 KB |
testcase_25 | AC | 359 ms
24,108 KB |
ソースコード
#include <iostream> #include <vector> #include <algorithm> #include <string> #include <numeric> #include <utility> #include <tuple> #define REP(i, a, b) for (int i = int(a); i < int(b); i++) using namespace std; using ll = long long int; using P = pair<ll, ll>; // clang-format off #ifdef _DEBUG_ #define dump(...) do{ cerr << __LINE__ << ":\t" << #__VA_ARGS__ << " = "; PPPPP(__VA_ARGS__); cerr << endl; } while(false) template<typename T> void PPPPP(T t) { cerr << t; } template<typename T, typename... S> void PPPPP(T t, S... s) { cerr << t << ", "; PPPPP(s...); } #else #define dump(...) do{ } while(false) #endif template<typename T> vector<T> make_v(size_t a, T b) { return vector<T>(a, b); } template<typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v(ts...))>(a, make_v(ts...)); } template<typename T> bool chmin(T &a, T b) { if (a > b) {a = b; return true; } return false; } template<typename T> bool chmax(T &a, T b) { if (a < b) {a = b; return true; } return false; } template<typename T> void print(T a) { cout << a << endl; } template<typename T, typename... Ts> void print(T a, Ts... ts) { cout << a << ' '; print(ts...); } template<typename T> istream &operator,(istream &in, T &t) { return in >> t; } // clang-format on #include <queue> using T = tuple<ll, int, int>; int main() { cin.tie(nullptr); ios::sync_with_stdio(false); int n, m; cin, n, m; vector<vector<P>> G(n); REP(i, 0, m) { int a, b, c; cin, a, b, c; a--; b--; G[a].emplace_back(b, c); G[b].emplace_back(a, c); } priority_queue<T, vector<T>, greater<T>> pq; // cost, to, used; pq.emplace(0, 0, 0); const ll inf = 1LL << 60; auto dp = make_v(2, n, inf); dp[0][0] = dp[1][0] = 0; while (pq.size()) { auto [cost, to, used] = pq.top(); pq.pop(); if (dp[used][to] < cost) continue; dp[used][to] = cost; for (auto [nto, ncost] : G[to]) { if (!used) { if (chmin(dp[1][nto], dp[used][to])) { pq.emplace(dp[1][nto], nto, 1); } } if (chmin(dp[used][nto], dp[used][to] + ncost)) { pq.emplace(dp[used][nto], nto, used); } } } REP(i, 0, n) { cout << dp[0][i] + dp[1][i] << endl; } return 0; }