結果

問題 No.160 最短経路のうち辞書順最小
ユーザー zeosuttzeosutt
提出日時 2015-05-05 20:34:43
言語 C90
(gcc 11.4.0)
結果
AC  
実行時間 13 ms / 5,000 ms
コード長 847 bytes
コンパイル時間 257 ms
コンパイル使用メモリ 25,332 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-19 07:04:28
合計ジャッジ時間 1,685 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <stdio.h>

#define INF 1000000000

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

int d[200][200], G[200][200];

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

	cur = start;
	while (cur != goal) {
		printf("%d ", cur);

		for (i = 0; i < n; i++)
			if (i != cur && G[cur][i] + d[i][goal] == d[cur][goal]) {
				cur = i;
				break;
			}
	}
	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] = G[i][j] = (i == j ? 0 : INF);

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

	for (k = 0; k < n; k++)
		for (i = 0; i < n; i++)
			for (j = 0; j < n; j++)
				d[i][j] = min(d[i][j], d[i][k] + d[k][j]);

	printPath(n, s, g);

	return 0;
}
0