結果
| 問題 | No.17 2つの地点に泊まりたい | 
| コンテスト | |
| ユーザー |  saytakaPC | 
| 提出日時 | 2015-09-06 05:58:32 | 
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 3 ms / 5,000 ms | 
| コード長 | 652 bytes | 
| コンパイル時間 | 1,277 ms | 
| コンパイル使用メモリ | 158,936 KB | 
| 実行使用メモリ | 5,248 KB | 
| 最終ジャッジ日時 | 2024-10-15 01:26:25 | 
| 合計ジャッジ時間 | 2,174 ms | 
| ジャッジサーバーID (参考情報) | judge2 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 27 | 
ソースコード
#include <bits/stdc++.h>
#define PB push_back
#define MP make_pair
using namespace std;
typedef long long ll;
int cost[50][50];
#define INF 100000000
int main(){
	int n,m,s[50];
	for(int i=0;i<50;i++)
		for(int j=0;j<50;j++)
			cost[i][j]=INF;
	cin>>n;
	for(int i=0;i<n;i++)cin>>s[i];
	cin>>m;
	for(int i=0;i<m;i++){
		int a,b,c;
		cin>>a>>b>>c;
		cost[a][b]=cost[b][a]=c;
	}
	for(int k=0;k<n;k++)
		for(int i=0;i<n;i++)
			for(int j=0;j<n;j++)
				cost[i][j]=min(cost[i][j],cost[i][k]+cost[k][j]);
	int ans=INF;
	for(int i=1;i<n-1;i++)
		for(int j=1;j<n-1;j++)
			if(i!=j)ans=min(ans,cost[0][i]+cost[i][j]+cost[j][n-1]+s[i]+s[j]);
	cout<<ans<<endl;
}
            
            
            
        