結果

問題 No.807 umg tours
ユーザー lumc_lumc_
提出日時 2019-03-22 21:51:20
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 194 ms / 4,000 ms
コード長 1,547 bytes
コンパイル時間 1,168 ms
コンパイル使用メモリ 121,092 KB
実行使用メモリ 18,448 KB
最終ジャッジ日時 2023-08-15 11:55:17
合計ジャッジ時間 4,774 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,384 KB
testcase_01 AC 2 ms
4,384 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,384 KB
testcase_06 AC 2 ms
4,384 KB
testcase_07 AC 1 ms
4,384 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 1 ms
4,384 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 102 ms
10,972 KB
testcase_12 AC 101 ms
11,136 KB
testcase_13 AC 138 ms
12,912 KB
testcase_14 AC 61 ms
7,612 KB
testcase_15 AC 44 ms
6,692 KB
testcase_16 AC 139 ms
13,412 KB
testcase_17 AC 188 ms
18,012 KB
testcase_18 AC 185 ms
17,696 KB
testcase_19 AC 176 ms
15,032 KB
testcase_20 AC 94 ms
11,036 KB
testcase_21 AC 96 ms
11,112 KB
testcase_22 AC 37 ms
6,780 KB
testcase_23 AC 29 ms
5,984 KB
testcase_24 AC 91 ms
16,700 KB
testcase_25 AC 194 ms
18,448 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

// includes {{{
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<tuple>
#include<cmath>
#include<random>
#include<cassert>
// #include<deque>
// #include<multiset>
// #include<bitset>
// #include<cstring>
// #include<bits/stdc++.h>
// }}}
using namespace std;
using ll = long long;

const int N = 1e5;
std::vector<std::vector<pair<int, int>>> g;
int n, m;
int main() {
  std::ios::sync_with_stdio(false), std::cin.tie(0);
  cin >> n >> m;
  g.resize(n);
  for(int i = 0; i < m; i++) {
    int a, b, c; std::cin >> a >> b >> c;
    a--; b--;
    g[a].emplace_back(b, c);
    g[b].emplace_back(a, c);
  }

  vector< ll > dist(n * 2, 1e18);
  // dijkstra {{{
  {
    using P = tuple< ll, int, int >;
    priority_queue< P, vector< P >, greater< P > > pq;
    pq.emplace(0, 0, 0);
    dist[0] = 0;
    dist[n] = 0;
    while(pq.size()) {
      ll di;
      int used, i;
      tie(di, used, i) = pq.top();
      pq.pop();
      if(dist[i] < di) continue;
      for(auto to : g[i - used * n]) {
        int j, co;
        tie(j, co) = to;
        j = j + used * n;
        ll ndi = di + co;
        if(dist[j] > ndi) {
          dist[j] = ndi;
          pq.emplace(ndi, used, j);
        }
        if(used == 0) {
          if(dist[j + n] > di) {
            dist[j + n] = di;
            pq.emplace(di, 1, j + n);
          }
        }
      }
    }
  }
  // }}}
  
  for(int i = 0; i < n; i++) {
    cout << dist[i] + dist[i + n] << "\n";
  }
  return 0;
}
0