結果

問題 No.807 umg tours
ユーザー oxyshoweroxyshower
提出日時 2020-01-13 22:25:38
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 421 ms / 4,000 ms
コード長 1,154 bytes
コンパイル時間 2,308 ms
コンパイル使用メモリ 182,840 KB
実行使用メモリ 24,652 KB
最終ジャッジ日時 2023-08-15 12:40:47
合計ジャッジ時間 7,496 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,384 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,384 KB
testcase_03 AC 2 ms
4,384 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 240 ms
16,280 KB
testcase_12 AC 240 ms
15,576 KB
testcase_13 AC 310 ms
17,892 KB
testcase_14 AC 136 ms
9,864 KB
testcase_15 AC 109 ms
8,272 KB
testcase_16 AC 319 ms
18,924 KB
testcase_17 AC 409 ms
23,096 KB
testcase_18 AC 415 ms
23,460 KB
testcase_19 AC 411 ms
20,016 KB
testcase_20 AC 252 ms
12,660 KB
testcase_21 AC 258 ms
13,200 KB
testcase_22 AC 108 ms
7,596 KB
testcase_23 AC 85 ms
6,436 KB
testcase_24 AC 270 ms
21,648 KB
testcase_25 AC 421 ms
24,652 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#ifdef LOCAL_DEBUG
  #include "LOCAL_DEBUG.hpp"
#endif
#define int long long
const int INF = 1LL << 60;

struct edge{ int to,cost; };
typedef tuple<int, int, int> P;

signed 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<P,vector<P>,greater<P>> que;
  vector<vector<int>> dp(2, vector<int>(n, INF));
  dp[0][0] = dp[1][0] = 0;
  que.push({0, 0, 0}); //{最短距離,頂点}

  while( !que.empty() ){
    P p = que.top(); que.pop();
    int d = get<0>(p), u = get<1>(p), flag = get<2>(p);
    if(dp[flag][u] < d) continue;
    for(auto e : G[u]){
      if(dp[flag][e.to] > dp[flag][u] + e.cost){
        dp[flag][e.to] = dp[flag][u] + e.cost;
        que.push( {dp[flag][e.to], e.to, flag} );
      }
      if(flag == 0 && dp[1][e.to] > dp[0][u]){
        dp[1][e.to] = dp[0][u];
        que.push( {dp[1][e.to], e.to, 1} );
      }
    }
  }

  for(int i = 0; i < n; i++){
    cout << dp[0][i] + dp[1][i] << endl;
  }

  return 0;
}
0