結果

問題 No.807 umg tours
ユーザー yataro800yataro800
提出日時 2023-01-19 21:32:08
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 607 ms / 4,000 ms
コード長 1,683 bytes
コンパイル時間 4,493 ms
コンパイル使用メモリ 238,192 KB
実行使用メモリ 28,404 KB
最終ジャッジ日時 2023-09-04 14:18:02
合計ジャッジ時間 13,415 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,384 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,380 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 2 ms
4,380 KB
testcase_09 AC 2 ms
4,384 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 294 ms
16,496 KB
testcase_12 AC 338 ms
17,644 KB
testcase_13 AC 438 ms
19,728 KB
testcase_14 AC 177 ms
10,964 KB
testcase_15 AC 135 ms
9,176 KB
testcase_16 AC 455 ms
20,744 KB
testcase_17 AC 596 ms
28,284 KB
testcase_18 AC 583 ms
28,380 KB
testcase_19 AC 592 ms
23,544 KB
testcase_20 AC 350 ms
16,060 KB
testcase_21 AC 361 ms
16,544 KB
testcase_22 AC 141 ms
9,192 KB
testcase_23 AC 108 ms
7,660 KB
testcase_24 AC 310 ms
25,368 KB
testcase_25 AC 607 ms
28,404 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <math.h>

#include <algorithm>
#include <array>
#include <atcoder/all>
#include <bitset>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <sstream>
#include <vector>

using namespace std;
using namespace atcoder;

using Graph = vector<vector<int>>;

using ll = long long;
typedef pair<ll, ll> P_ll;
typedef pair<int, int> P;

const ll INF_ll = 1e17;
const int INF = 1e8;
template <class T>
bool chmax(T& a, const T& b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmin(T& a, const T& b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename T>
using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;

int main() {
  int N, M;
  cin >> N >> M;
  vector<vector<P_ll>> G(N);
  for (int i = 0; i < M; i++) {
    ll a, b, c;
    cin >> a >> b >> c;
    a--;
    b--;
    G[a].push_back({b, c});
    G[b].push_back({a, c});
  }
  vector<vector<ll>> dist(N, vector<ll>(2, INF_ll));
  min_priority_queue<pair<P_ll, ll>> pq;
  dist[0][0] = 0;
  pq.push({{0, 0}, 0});
  while (!pq.empty()) {
    auto p = pq.top();
    pq.pop();
    ll d = p.first.first;
    ll c = p.first.second;
    ll u = p.second;
    if (dist[u][c] < d) {
      continue;
    }

    for (auto e : G[u]) {
      ll next = e.first;
      if (chmin(dist[next][c], e.second + d)) {
        pq.push({{dist[next][c], c}, next});
      }
      if (c == 0) {
        if (chmin(dist[next][1], d)) {
          pq.push({{dist[next][1], 1}, next});
        }
      }
    }
  }
  for (int i = 0; i < N; i++) {
    cout << dist[i][0] + min(dist[i][0], dist[i][1]) << endl;
  }

  return 0;
}
0