結果

問題 No.17 2つの地点に泊まりたい
ユーザー kapokapo
提出日時 2016-05-30 15:00:23
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 3 ms / 5,000 ms
コード長 902 bytes
コンパイル時間 430 ms
コンパイル使用メモリ 60,404 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-05 03:46:17
合計ジャッジ時間 1,582 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <algorithm>

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

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