結果

問題 No.17 2つの地点に泊まりたい
ユーザー こるこる
提出日時 2017-02-16 19:06:51
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 991 bytes
コンパイル時間 517 ms
コンパイル使用メモリ 64,028 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-05 03:50:26
合計ジャッジ時間 1,727 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include<iostream>
#include<string>
#include<vector>
#include<set>
#include<algorithm>
#define ll long long
#define PLL pair<ll,ll>
#define VS vector<string>
#define VLL vector<ll,ll>
#define rep(i,a) for (ll i=0;i<a;i++)
#define nrep(i,n,a) for (ll i=n;i<a;i++)
#define INF 1145141919810
#define VMIN(vec) *std::max_element(vec.begin(),vec.end())
#define VMIN(vec) *std::max_element(vec.begin(),vec.end())
#define OUT(n) cout<<n<<endl
#define TS(n) to_string(n)

using namespace std;

ll dist[51][51];

void floyd(ll 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() {
	ll n; cin>>n;
	ll s[50],a,b,c;
	rep(i, n) cin>>s[i];
	ll m; cin>>m;
	rep(i, n) rep(j, n) dist[i][j] = INF;
	rep(i, m){
		cin>>a>>b>>c;
		dist[a][b] = dist[b][a] = c;
	}
	floyd(n);
	ll temp ,ans=INF;
	nrep(i, 1, n - 1) nrep(j, 1, n - 1) if (i != j) {
			temp = dist[0][i] + dist[i][j] + dist[j][n - 1] + s[i] + s[j];
			ans = min(ans, temp);
	}OUT(ans);
	return 0;
}
0