結果

問題 No.807 umg tours
ユーザー pekempeypekempey
提出日時 2019-03-22 23:05:13
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 397 ms / 4,000 ms
コード長 1,125 bytes
コンパイル時間 1,179 ms
コンパイル使用メモリ 89,460 KB
実行使用メモリ 21,792 KB
最終ジャッジ日時 2023-08-15 12:05:45
合計ジャッジ時間 6,491 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,384 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,384 KB
testcase_04 AC 2 ms
4,384 KB
testcase_05 AC 2 ms
4,384 KB
testcase_06 AC 2 ms
4,384 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 1 ms
4,384 KB
testcase_09 AC 2 ms
4,384 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 237 ms
14,932 KB
testcase_12 AC 209 ms
13,172 KB
testcase_13 AC 286 ms
16,168 KB
testcase_14 AC 118 ms
9,292 KB
testcase_15 AC 87 ms
7,800 KB
testcase_16 AC 306 ms
16,956 KB
testcase_17 AC 397 ms
21,132 KB
testcase_18 AC 386 ms
21,404 KB
testcase_19 AC 366 ms
19,048 KB
testcase_20 AC 182 ms
12,116 KB
testcase_21 AC 193 ms
12,708 KB
testcase_22 AC 73 ms
7,352 KB
testcase_23 AC 56 ms
6,308 KB
testcase_24 AC 165 ms
16,228 KB
testcase_25 AC 370 ms
21,792 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <tuple>

using namespace std;

#define REP(i, n) for (int i = 0; i < (n); i++)

const long long INF = 1e18;

struct edge {
  int v;
  long long w;
};

long long dp[100000][2];

int main() {
  int N, M;
  cin >> N >> M;
  vector<vector<edge>> G(N);
  for (int i = 0; i < M; i++) {
    int a, b, c;
    cin >> a >> b >> c;
    a--; b--;
    G[a].push_back({b, c});
    G[b].push_back({a, c});
  }
  priority_queue<tuple<long long, int, int>> q;
  REP(i, N) REP(j, 2) dp[i][j] = INF;
  dp[0][0] = 0;
  dp[0][1] = 0;
  q.emplace(0, 0, 0);
  while (!q.empty()) {
    long long d;
    int i, j;
    tie(d, i, j) = q.top(); q.pop();
    if (dp[i][j] < -d) continue;
    for (edge e : G[i]) {
      if (dp[e.v][j] > dp[i][j] + e.w) {
        dp[e.v][j] = dp[i][j] + e.w;
        q.emplace(-dp[e.v][j], e.v, j);
      }
      if (j == 0) {
        if (dp[e.v][1] > dp[i][j]) {
          dp[e.v][1] = dp[i][j];
          q.emplace(-dp[e.v][1], e.v, 1);
        }
      }
    }
  }
  REP(i, N) cout << dp[i][0] + dp[i][1] << '\n';
}
0