結果

問題 No.160 最短経路のうち辞書順最小
ユーザー TLwiegehttTLwiegehtt
提出日時 2015-07-15 09:16:49
言語 C90
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,004 bytes
コンパイル時間 642 ms
コンパイル使用メモリ 25,252 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-09-22 16:08:39
合計ジャッジ時間 2,319 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <stdio.h>

#define VMAX	(202)
#define INF		(99999)

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