結果

問題 No.807 umg tours
ユーザー pekempeypekempey
提出日時 2019-03-22 23:05:13
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 351 ms / 4,000 ms
コード長 1,125 bytes
コンパイル時間 927 ms
コンパイル使用メモリ 90,840 KB
実行使用メモリ 21,212 KB
最終ジャッジ日時 2024-05-02 23:31:14
合計ジャッジ時間 5,713 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 3 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 218 ms
15,160 KB
testcase_12 AC 181 ms
13,476 KB
testcase_13 AC 259 ms
16,564 KB
testcase_14 AC 111 ms
9,588 KB
testcase_15 AC 81 ms
7,936 KB
testcase_16 AC 279 ms
17,260 KB
testcase_17 AC 331 ms
21,164 KB
testcase_18 AC 342 ms
21,212 KB
testcase_19 AC 331 ms
19,320 KB
testcase_20 AC 163 ms
12,416 KB
testcase_21 AC 161 ms
12,672 KB
testcase_22 AC 65 ms
7,424 KB
testcase_23 AC 53 ms
6,528 KB
testcase_24 AC 156 ms
16,428 KB
testcase_25 AC 351 ms
21,016 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