結果

問題 No.160 最短経路のうち辞書順最小
ユーザー TLwiegehttTLwiegehtt
提出日時 2015-07-15 09:20:10
言語 C90
(gcc 11.4.0)
結果
AC  
実行時間 13 ms / 5,000 ms
コード長 1,007 bytes
コンパイル時間 155 ms
コンパイル使用メモリ 25,344 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-22 16:08:41
合計ジャッジ時間 1,519 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <stdio.h>

#define VMAX	(202)
#define INF		(99999999)

int length[VMAX][VMAX];
int dis[VMAX][VMAX];

int min(int a, int b){
	if(a<b){return a;}
	return b;
}

int main(void){
	int i,j,k;
	int nodeMax, loadMax, stPos, goPos;
	
	for(i=0;i<VMAX;i++){
		for(j=0;j<VMAX;j++){
			length[i][j] = INF;
			dis[i][j] = INF;
		}
	}
	
	scanf("%d %d %d %d", &nodeMax, &loadMax, &stPos, &goPos);
	for(i=0;i<loadMax;i++){
		int a,b,c;
		scanf("%d %d %d", &a, &b,&c);
		if( i != stPos ){
		}
		length[a][b] = c;
		length[b][a] = c;
		dis[a][b] = c;
		dis[b][a] = c;
	}
	
	for(k=0;k<nodeMax;k++){
		for(i=0;i<nodeMax;i++){
			for(j=0;j<nodeMax;j++){
				length[i][j] = min( length[i][j], length[i][k] + length[k][j]);
			}
		}
	}
	for(i=0;i<VMAX;i++){
		length[i][i] = 0;
	}
	
	k = stPos;
	while(k != goPos){
		printf("%d ", k);
		for(i=0;i<nodeMax;i++){
			if( i == k){continue;}
			if( i!= k && dis[k][i] + length[i][goPos] == length[k][goPos]){
				k=i;
				break;
			}
		}
	}
	printf("%d\n", goPos);
	return 0;
}
0