結果

問題 No.807 umg tours
ユーザー 0w10w1
提出日時 2020-12-19 16:56:41
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 555 ms / 4,000 ms
コード長 992 bytes
コンパイル時間 3,510 ms
コンパイル使用メモリ 220,016 KB
実行使用メモリ 30,384 KB
最終ジャッジ日時 2023-10-21 09:22:24
合計ジャッジ時間 9,347 ms
ジャッジサーバーID
(参考情報)
judge12 / judge9
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 198 ms
14,056 KB
testcase_12 AC 267 ms
17,488 KB
testcase_13 AC 359 ms
19,600 KB
testcase_14 AC 137 ms
11,944 KB
testcase_15 AC 77 ms
9,040 KB
testcase_16 AC 360 ms
18,464 KB
testcase_17 AC 555 ms
26,084 KB
testcase_18 AC 502 ms
24,844 KB
testcase_19 AC 457 ms
22,240 KB
testcase_20 AC 199 ms
15,112 KB
testcase_21 AC 218 ms
15,640 KB
testcase_22 AC 73 ms
8,776 KB
testcase_23 AC 54 ms
7,456 KB
testcase_24 AC 161 ms
24,660 KB
testcase_25 AC 549 ms
30,384 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int main() {
  ios::sync_with_stdio(false);

  int N, M; { cin >> N >> M; }

  vector<vector<pair<int, int>>> G(N); {
    for (int i = 0; i < M; ++i) {
      int A, B, C; { cin >> A >> B >> C; --A, --B; }
      G[A].emplace_back(C, B);
      G[B].emplace_back(C, A);
    }
  }

  const int64_t INF = (int64_t) 1 << 60;

  vector<vector<int64_t>> dis(N, vector<int64_t>(2, INF)); {
    set<tuple<int64_t, int, int>> bag;
    bag.emplace(dis[0][0] = 0, 0, 0);
    while (bag.size()) {
      auto [d, u, t] = *bag.begin();
      bag.erase(bag.begin());

      if (dis[u][t] != d) continue;

      for (auto [w, v] : G[u]) {
        if (dis[v][t] > d + w) {
          bag.emplace(dis[v][t] = d + w, v, t);
        }
        if (t == 0 && dis[v][1] > d) {
          bag.emplace(dis[v][1] = d, v, 1);
        }
      }
    }
  }

  for (int i = 0; i < N; ++i) {
    int64_t res = dis[i][0] + min(dis[i][0], dis[i][1]);
    cout << res << "\n";
  }
}

0