結果

問題 No.160 最短経路のうち辞書順最小
ユーザー TwizzTwizz
提出日時 2017-05-25 20:27:19
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,136 bytes
コンパイル時間 1,403 ms
コンパイル使用メモリ 162,856 KB
実行使用メモリ 4,372 KB
最終ジャッジ日時 2023-10-19 23:20:26
合計ジャッジ時間 2,537 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include"bits/stdc++.h"

//#include<bits/stdc++.h>
using namespace std;
#define print(x) cout<<x<<endl;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a) for(int i=0;i<a;i++)
typedef long long ll;
typedef pair<int, int> PI;
typedef pair<int, PI> V;
const ll mod = 100000000;

int n, m, s, g;
int a[20000], b[20000], c[20000];
int d[202];
bool used[202];
int cost[202][202];

void dijkstra(int s) {
	REP(i, n)d[i] = mod;
	REP(i, n)used[i] = 0;
	d[s] = 0;

	while (true) {
		int v = -1;
		REP(u, n) {
			if (!used[u] && (v == -1 || d[u] < d[v]))v = u;
		}
		if (v == -1)break;
		used[v] = true;
		REP(u, n) {
			d[u] = min(d[u], d[v] + cost[v][u]);
		}
	}
}

int main() {
	cin >> n >> m >> s >> g;
	REP(i, 202)REP(j, 202)cost[i][j] = mod;
	REP(i, m) {
		cin >> a[i] >> b[i] >> c[i];
		cost[a[i]][b[i]] = c[i];
		cost[b[i]][a[i]] = c[i];
	}
	dijkstra(s);
	vector<int> v;
	v.push_back(g);
	int now = g;
	while (now != s) {
		rep(i, 0, n) {
			if (d[i] == d[now] - cost[i][now]) {
				now = i;
				v.push_back(i);
			}
		}
	}
	reverse(v.begin(), v.end());
	//print(d[g]);
	REP(i,v.size())cout<<v[i] << " ";
	cout << endl;
	return 0;
}
0