結果

問題 No.17 2つの地点に泊まりたい
ユーザー ynq1242ynq1242
提出日時 2014-10-29 17:49:12
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 1,601 bytes
コンパイル時間 878 ms
コンパイル使用メモリ 84,964 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-23 01:59:20
合計ジャッジ時間 1,750 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 2 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 1 ms
5,376 KB
testcase_14 AC 2 ms
5,376 KB
testcase_15 AC 2 ms
5,376 KB
testcase_16 AC 2 ms
5,376 KB
testcase_17 AC 2 ms
5,376 KB
testcase_18 AC 2 ms
5,376 KB
testcase_19 AC 2 ms
5,376 KB
testcase_20 AC 1 ms
5,376 KB
testcase_21 AC 2 ms
5,376 KB
testcase_22 AC 2 ms
5,376 KB
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 <fstream>
#include <stdio.h>
#include <stdlib.h>
#define _USE_MATH_DEFINES
#include <math.h>
#include<string>
#include<vector>
#include<cmath>
#include<stack>
#include<queue>
#include<list>
#include<sstream>
#include<algorithm>
#include<map>
#include<complex>
#include<ctime>
#include<set>
using namespace std;


#define li			long long int
#define rep(i,to)	for(li i=0;i<((li)(to));i++)
#define repp(i,start,to)	for(li i=(li)(start);i<((li)(to));i++)
#define pb			push_back
#define sz(v)		((li)(v).size())
#define bgn(v)		((v).begin())
#define eend(v)		((v).end())
#define allof(v)	(v).begin(), (v).end()
#define dodp(v,n)		memset(v,(li)n,sizeof(v))
#define bit(n)		(1ll<<(li)(n))
#define mp(a,b)		make_pair(a,b)
#define rin	rep(i,n)
#define EPS 1e-10
#define ETOL 1e-8
#define MOD 1000003
#define INF 10000000000000000
#define F first
#define S second
#define endl "\n"
#define pp(X)		cout<<X.F<<"\t"<<X.S<<endl
#define p2(a,b)		cout<<a<<"\t"<<b<<endl
#define p3(a,b,c)		cout<<a<<"\t"<<b<<"\t"<<c<<endl

li s[55];
vector<li> edge[55];
li wf[55][55];

int main(){
	ios::sync_with_stdio(false);

	li n;
	cin>>n;
	rep(i,n)cin>>s[i];
	rep(i,n)rep(j,n)wf[i][j]=INF;
	li m;
	cin>>m;
	rep(i,m){
		li a,b,c;
		cin>>a>>b>>c;
		wf[a][b]=wf[b][a]=c;
	}

	rep(k,n){
		rep(i,n){
			rep(j,n){
				wf[i][j]=min(wf[i][j], wf[i][k]+wf[k][j]);
			}
		}
	}

	li res=INF;

	repp(i,1,n-1){
		repp(j,1,n-1){
			if(i!=j)res=min(res, wf[0][i]+wf[i][j]+wf[j][n-1]+s[i]+s[j]);
		}
	}

	cout<<res<<endl;

	return 0;
}
0