結果

問題 No.17 2つの地点に泊まりたい
ユーザー Ysmr_RyYsmr_Ry
提出日時 2014-11-11 00:47:36
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 762 bytes
コンパイル時間 349 ms
コンパイル使用メモリ 39,640 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-05 03:30:00
合計ジャッジ時間 1,439 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include<cstdio>
#include<algorithm>
#include<limits>
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)

const int MAX_N = 50, INF = std::numeric_limits<int>::max()>>2;

int N, M;
int S[MAX_N], d[MAX_N][MAX_N];

int main()
{
	scanf( "%d", &N );
	rep( i, N )
		scanf( "%d", S+i );
	
	rep( i, N ) rep( j, N )
		d[i][j] = i==j?0:INF;
	
	scanf( "%d", &M );
	rep( i, M )
	{
		int A, B, C;
		scanf( "%d%d%d", &A, &B, &C );
		d[A][B] = d[B][A] = C;
	}

	rep( k, N ) rep( i, N ) rep( j, N )
		d[i][j] = std::min( d[i][j], d[i][k]+d[k][j] );

	int ans = INF;
	repi( i, 1, N-1 ) repi( j, 1, N-1 ) if( i != j )
		ans = std::min( ans, d[0][i]+S[i]+d[i][j]+S[j]+d[j][N-1] );

	printf( "%d\n", ans );

	return 0;
}
0