結果

問題 No.17 2つの地点に泊まりたい
ユーザー kapokapo
提出日時 2016-05-30 14:55:19
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 902 bytes
コンパイル時間 477 ms
コンパイル使用メモリ 57,840 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-16 18:40:44
合計ジャッジ時間 1,290 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <algorithm>

#define rep(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
#define INF 1e9

int main(void)
{
	int N, M;
	cin >> N;
	int S[50];
	rep(i,0,N) cin >> S[i];

	cin >> M;
	int G[50][50];
	int from, to, cost;
	rep(i,0,N) rep(j,0,N) G[i][j] = INF;
	rep(i,0,M) {
		cin >> from >> to >> cost;
		G[from][to] = min(G[from][to], cost);
		G[to][from] = G[from][to];
	}

	rep(i,0,N) G[i][i] = 0;
	rep(k,0,N) rep(i,0,N) rep(j,0,N) {
		if(G[i][j] > G[i][k] + G[k][j]) G[i][j] = G[i][k] + G[k][j];
	}

	// rep(i,0,N) rep(j,0,N) printf("G[%d][%d] = %d\n",i,j,G[i][j]);

	int ans = INF;
	rep(i,1,N-1) rep(j,1,N-1) {
		if(i == j) continue;
		if(ans > G[0][i] + G[i][j] + G[j][N-1] + S[i] +S[j]) {
			ans = G[0][i] + G[i][j] + G[j][N-1] + S[i] +S[j];
			// printf("i=%d j=%d ans=%d\n",i,j,G[0][i] + G[i][j] + G[j][N-1] + S[i] +S[j]);
		}
	}

	cout << ans << endl;

	return 0;
}
0