結果
| 問題 | No.17 2つの地点に泊まりたい | 
| コンテスト | |
| ユーザー |  srup٩(๑`н´๑)۶ | 
| 提出日時 | 2016-07-19 21:25:04 | 
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) | 
| 結果 | 
                                WA
                                 
                             | 
| 実行時間 | - | 
| コード長 | 1,272 bytes | 
| コンパイル時間 | 578 ms | 
| コンパイル使用メモリ | 60,276 KB | 
| 実行使用メモリ | 6,820 KB | 
| 最終ジャッジ日時 | 2024-10-15 17:25:01 | 
| 合計ジャッジ時間 | 1,845 ms | 
| ジャッジサーバーID (参考情報) | judge2 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 21 WA * 6 | 
ソースコード
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
const int MAX_N = 51, INF = 1e9;
int s[MAX_N];
int dist[MAX_N][MAX_N];
//ワーシャルフロイド法 全点対間最短経路をもとめるとき) (0オリジン)
//dist[i][i] = 0 dist[i][j](経路がないもの)= dist[j][i] = INF(1e9)で初期化しておくこと
//dist[i][j] = dist[j][i] = (距離)を代入しておくこと
//この関数を利用することで、dist[i][j]の値(i,j間の距離)の最小値に更新されていく
void floyd (int n){//nは頂点の数
	rep(k, n) rep(i, n) rep(j, n)
		dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
}
int main(void){
	rep(i, MAX_N)rep(j, MAX_N) dist[i][j] = dist[j][i] = INF;
	rep(i, MAX_N) dist[i][i] = 0;
	int n; cin >> n;
	rep(i, n) cin >> s[i];
	int m; cin >> m;
	rep(i, m){
		int a, b, c; cin >> a >> b >> c;
		dist[a][b] = dist[b][a] = c;
	}
	floyd(n);
	// rep(i, n)rep(j, n) printf("dist[%d][%d] = %d\n", i, j, dist[i][j]);
	int ans = INF, tmp;
	for (int i = 1; i < n - 1; ++i){
		for (int j = 1; j < n - 1; ++j){
			if(i != j){
				tmp = dist[0][i] + dist[i][j] + dist[j][n - 1] + s[i] + s[j];
				ans = min(ans, tmp);
			}
		}
	}
	cout << ans << endl;
	return 0;
}
            
            
            
        