結果

問題 No.160 最短経路のうち辞書順最小
ユーザー zeosuttzeosutt
提出日時 2015-05-05 04:44:59
言語 C90
(gcc 11.4.0)
結果
AC  
実行時間 14 ms / 5,000 ms
コード長 907 bytes
コンパイル時間 945 ms
コンパイル使用メモリ 25,640 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-19 07:00:31
合計ジャッジ時間 2,851 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <stdio.h>

#define INF 1000000000

#define min(a, b) (((a) < (b)) ? (a) : (b))

int d[200][200];
int next[200][200];

void printPath(int start, int goal) {
	int cur;

	for (cur = start; cur != goal; cur = next[cur][goal])
		printf("%d ", cur);
	printf("%d\n", goal);
}

int main(void) {
	int i, j, k;
	int n, m, s, g;

	scanf("%d %d %d %d", &n, &m, &s, &g);

	for (i = 0; i < n; i++)
		for (j = 0; j < n; j++)
			d[i][j] = INF;

	while (m--) {
		int a, b, c;
		scanf("%d %d %d", &a, &b, &c);
		d[a][b] = d[b][a] = c;
	}

	for (i = 0; i < n; i++)
		for (j = 0; j < n; j++)
			next[i][j] = j;

	for (k = 0; k < n; k++)
		for (i = 0; i < n; i++)
			for (j = 0; j < n; j++)
				if (d[i][k] + d[k][j] < d[i][j]) {
					d[i][j] = d[i][k] + d[k][j];
					next[i][j] = next[i][k];
				} else if (d[i][k] + d[k][j] == d[i][j])
					next[i][j] = min(next[i][j], next[i][k]);

	printPath(s, g);

	return 0;
}
0