結果

問題 No.807 umg tours
ユーザー lumc_lumc_
提出日時 2019-03-22 21:51:20
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 281 ms / 4,000 ms
コード長 1,547 bytes
コンパイル時間 1,551 ms
コンパイル使用メモリ 121,216 KB
実行使用メモリ 17,396 KB
最終ジャッジ日時 2024-05-02 23:20:56
合計ジャッジ時間 5,622 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 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 2 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 131 ms
11,180 KB
testcase_12 AC 134 ms
11,336 KB
testcase_13 AC 198 ms
13,136 KB
testcase_14 AC 80 ms
7,780 KB
testcase_15 AC 60 ms
6,784 KB
testcase_16 AC 194 ms
13,620 KB
testcase_17 AC 281 ms
17,264 KB
testcase_18 AC 275 ms
17,396 KB
testcase_19 AC 259 ms
15,308 KB
testcase_20 AC 140 ms
10,880 KB
testcase_21 AC 141 ms
11,136 KB
testcase_22 AC 48 ms
6,528 KB
testcase_23 AC 35 ms
5,888 KB
testcase_24 AC 102 ms
15,608 KB
testcase_25 AC 273 ms
17,168 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