結果

問題 No.807 umg tours
ユーザー oxyshoweroxyshower
提出日時 2020-01-13 22:25:38
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 419 ms / 4,000 ms
コード長 1,154 bytes
コンパイル時間 1,703 ms
コンパイル使用メモリ 182,588 KB
実行使用メモリ 24,512 KB
最終ジャッジ日時 2023-08-15 12:39:15
合計ジャッジ時間 8,280 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 270 ms
15,972 KB
testcase_12 AC 288 ms
15,108 KB
testcase_13 AC 376 ms
17,852 KB
testcase_14 AC 134 ms
10,024 KB
testcase_15 AC 104 ms
8,300 KB
testcase_16 AC 327 ms
18,624 KB
testcase_17 AC 419 ms
23,408 KB
testcase_18 AC 406 ms
23,356 KB
testcase_19 AC 392 ms
20,176 KB
testcase_20 AC 254 ms
12,976 KB
testcase_21 AC 256 ms
13,180 KB
testcase_22 AC 104 ms
7,632 KB
testcase_23 AC 80 ms
6,504 KB
testcase_24 AC 264 ms
21,100 KB
testcase_25 AC 403 ms
24,512 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