結果

問題 No.17 2つの地点に泊まりたい
ユーザー Ysmr_RyYsmr_Ry
提出日時 2014-11-11 00:47:36
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 1 ms / 5,000 ms
コード長 762 bytes
コンパイル時間 225 ms
コンパイル使用メモリ 37,336 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-23 01:59:40
合計ジャッジ時間 936 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,816 KB
testcase_01 AC 1 ms
6,940 KB
testcase_02 AC 0 ms
6,944 KB
testcase_03 AC 1 ms
6,940 KB
testcase_04 AC 0 ms
6,940 KB
testcase_05 AC 1 ms
6,944 KB
testcase_06 AC 1 ms
6,944 KB
testcase_07 AC 1 ms
6,944 KB
testcase_08 AC 1 ms
6,940 KB
testcase_09 AC 1 ms
6,944 KB
testcase_10 AC 0 ms
6,940 KB
testcase_11 AC 1 ms
6,944 KB
testcase_12 AC 0 ms
6,944 KB
testcase_13 AC 1 ms
6,944 KB
testcase_14 AC 0 ms
6,940 KB
testcase_15 AC 0 ms
6,940 KB
testcase_16 AC 0 ms
6,944 KB
testcase_17 AC 0 ms
6,940 KB
testcase_18 AC 1 ms
6,940 KB
testcase_19 AC 1 ms
6,940 KB
testcase_20 AC 0 ms
6,940 KB
testcase_21 AC 1 ms
6,940 KB
testcase_22 AC 1 ms
6,940 KB
testcase_23 AC 1 ms
6,940 KB
testcase_24 AC 1 ms
6,944 KB
testcase_25 AC 1 ms
6,940 KB
testcase_26 AC 1 ms
6,940 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:14:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   14 |         scanf( "%d", &N );
      |         ~~~~~^~~~~~~~~~~~
main.cpp:16:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   16 |                 scanf( "%d", S+i );
      |                 ~~~~~^~~~~~~~~~~~~
main.cpp:21:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   21 |         scanf( "%d", &M );
      |         ~~~~~^~~~~~~~~~~~
main.cpp:25:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   25 |                 scanf( "%d%d%d", &A, &B, &C );
      |                 ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~

ソースコード

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