結果

問題 No.160 最短経路のうち辞書順最小
ユーザー 0w10w1
提出日時 2016-11-27 20:42:09
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 17 ms / 5,000 ms
コード長 1,064 bytes
コンパイル時間 1,799 ms
コンパイル使用メモリ 181,532 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-18 08:31:11
合計ジャッジ時間 3,049 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 4 ms
4,384 KB
testcase_05 AC 7 ms
4,376 KB
testcase_06 AC 9 ms
4,380 KB
testcase_07 AC 3 ms
4,384 KB
testcase_08 AC 3 ms
4,376 KB
testcase_09 AC 3 ms
4,380 KB
testcase_10 AC 3 ms
4,380 KB
testcase_11 AC 3 ms
4,380 KB
testcase_12 AC 3 ms
4,380 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 3 ms
4,376 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 3 ms
4,380 KB
testcase_17 AC 3 ms
4,376 KB
testcase_18 AC 3 ms
4,376 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 3 ms
4,376 KB
testcase_21 AC 3 ms
4,384 KB
testcase_22 AC 3 ms
4,380 KB
testcase_23 AC 3 ms
4,376 KB
testcase_24 AC 3 ms
4,380 KB
testcase_25 AC 3 ms
4,380 KB
testcase_26 AC 3 ms
4,376 KB
testcase_27 AC 2 ms
4,376 KB
testcase_28 AC 17 ms
4,380 KB
testcase_29 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

template< class T1, class T2 >
int upmin( T1 &x, T2 v ){
  if( x > v ){
    x = v;
    return 1;
  }
  return 0;
}

signed main(){
  int N, M, S, G; cin >> N >> M >> S >> G;
  vector< vector< pair< int, int > > > E( N );
  for( int i = 0; i < M; ++i ){
    int A, B, C; cin >> A >> B >> C;
    E[ A ].emplace_back( C, B );
    E[ B ].emplace_back( C, A );
  }
  vector< pair< int, int > > dis( N, make_pair( 0x3f3f3f3f, -1 ) );
  priority_queue< tuple< int, int, int >, vector< tuple< int, int, int > >, greater< tuple< int, int, int > > > pq;
  dis[ G ] = make_pair( 0, -1 );
  pq.emplace( 0, -1, G );
  while( not pq.empty() ){
    int d, p, u; tie( d, p, u ) = pq.top(); pq.pop();
    if( make_pair( d, p ) != dis[ u ] ) continue;
    for( int i = 0; i < E[ u ].size(); ++i ){
      int w, v; tie( w, v ) = E[ u ][ i ];
      if( upmin( dis[ v ], make_pair( d + w, u ) ) )
        pq.emplace( d + w, u, v );
    }
  }
  for( int u = S; u != -1; u = dis[ u ].second )
    cout << u << " \n"[ u == G ];
  return 0;
}
0