結果

問題 No.160 最短経路のうち辞書順最小
ユーザー icchyricchyr
提出日時 2016-07-28 16:46:54
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 24 ms / 5,000 ms
コード長 1,139 bytes
コンパイル時間 1,545 ms
コンパイル使用メモリ 172,296 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-24 10:33:59
合計ジャッジ時間 2,665 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)
#define _all(arg) begin(arg),end(arg)

template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0; }
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0; }

using namespace std;
using vi=vector<int>;

const int INF=1<<28;

int S, G;

int main() {
	int N, M; cin >> N >> M >> S >> G;
	vector<vi> edge(N, vi(N, INF));
	vector<vi> dist;
	rep(i, M) {
		int a, b, c; cin >> a >> b >> c;
		edge[a][b] = edge[b][a] = c;
	}
	rep(i, N) { edge[i][i] = 0; }

	dist = edge;

	rep(k, N) rep(i, N) rep(j, N) {
		chmin(dist[i][j], dist[i][k] + dist[k][j]);
	}

	int cur = S;
	vector<int> res;
	res.push_back(S);
	while (cur != G) {
		rep(i, N) {
			if (i == cur) continue;
			if(dist[S][cur] + edge[cur][i] + dist[i][G] 
					== dist[S][G]) {
				cur = i;
				res.push_back(i);
				break;
			}
		}
	}

	rep(i, res.size()-1) { cout << res[i] << " "; }
	cout << res[res.size()-1] << endl;

	return 0;
}
0