結果

問題 No.160 最短経路のうち辞書順最小
コンテスト
ユーザー ooaiu
提出日時 2026-09-29 22:38:33
言語 C++23
(gcc 15.3.0 + boost 1.92.0 + ACL)
コンパイル:
g++-15 -O2 -lm -std=c++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 15 ms / 5,000 ms
+ 446µs
コード長 747 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,204 ms
コンパイル使用メモリ 174,940 KB
実行使用メモリ 9,872 KB
最終ジャッジ日時 2026-09-29 22:38:46
合計ジャッジ時間 4,028 ms
ジャッジサーバーID
(参考情報)
judge2_1 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 26
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <vector>
#include <iostream>
#include <cassert>
#include <algorithm>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
int N, M, s, t;
long D[202][202];
vector<pair<int,int>> G[202];
int main() {
	cin >> N >> M >> s >> t;
	rep(i, N) rep(j, N) D[i][j] = 1e9;
	rep(i, M) {
		int a, b, c;
		cin >> a >> b >> c;
		D[a][b] = c;
		D[b][a] = c;
		G[a].push_back({b,c});
		G[b].push_back({a,c});
	}
	rep(i,N)D[i][i]=0;
	rep(k,N)rep(i,N)rep(j,N)D[i][j]=min(D[i][j],D[i][k]+D[k][j]);
	vector<int> A;
	int it = s;
	A.push_back(it);
	while (it != t) {
		int nt=N;
		for(auto[nxt,cst]:G[it]) if(D[s][it]+cst+D[nxt][t]==D[s][t]){
			nt=min(nt,nxt);
		}
		A.push_back(nt);
		it=nt;
	}
	for(int x: A) cout << x << " ";
	cout<<endl;
}

0