結果
| 問題 | No.17 2つの地点に泊まりたい | 
| コンテスト | |
| ユーザー |  kapo | 
| 提出日時 | 2016-05-30 15:00:23 | 
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 3 ms / 5,000 ms | 
| コード長 | 902 bytes | 
| コンパイル時間 | 404 ms | 
| コンパイル使用メモリ | 57,944 KB | 
| 実行使用メモリ | 5,248 KB | 
| 最終ジャッジ日時 | 2024-10-15 01:34:47 | 
| 合計ジャッジ時間 | 1,159 ms | 
| ジャッジサーバーID (参考情報) | judge4 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 27 | 
ソースコード
#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;
}
            
            
            
        