結果

問題 No.17 2つの地点に泊まりたい
ユーザー ttkkggwwttkkggww
提出日時 2022-03-21 10:05:31
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 3 ms / 5,000 ms
コード長 980 bytes
コンパイル時間 4,572 ms
コンパイル使用メモリ 255,144 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-17 03:07:02
合計ジャッジ時間 5,196 ms
ジャッジサーバーID
(参考情報)
judge1 / 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 3 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 2 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 2 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<bits/stdc++.h>
using namespace std;
#include<atcoder/all>
using namespace atcoder;
using ll = long long;
int n,m;
vector<int> s;
vector<vector<pair<int,int>>> G;
int dist[50][50];
const int INF = INT_MAX/4;

void solve(){
	for(int k = 0;k<50;k++){
		for(int i = 0;i<50;i++){
			for(int j = 0;j<50;j++){
				dist[i][j] = min(dist[i][j],dist[i][k]+dist[k][j]);
			}
		}
	}
	int ans = INF;
	for(int i = 1;i<n-1;i++){
		for(int j = 1;j<n-1;j++){
			if(i==j)continue;
			int cur = 0;
			cur += dist[0][i] + dist[i][j] + dist[j][n-1];
			cur += s[i] + s[j];
			ans = min(ans,cur);
		}
	}
	cout<<ans<<endl;
}

signed main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cin >> n;
	s = vector<int>(n);
	for(auto &i:s)cin >> i;
	for(int i = 0;i<50;i++){
		for(int j = 0;j<50;j++){
			if(i!=j)
			dist[i][j] = INF;
		}
	}
	cin >> m;
	for(int i = 0;i<m;i++){
		int a,b,c;
		cin >> a >> b >> c;
		dist[a][b] = min(dist[a][b],c);
		dist[b][a] = min(dist[b][a],c);
	}
	solve();
}
0