結果

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

テストケース

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

ソースコード

diff #

#include"bits/stdc++.h"
//#include<bits/stdc++.h>
using namespace std;
#define print(x) cout<<x<<endl;
#define rep(i,a,b) for(int i=a;i<b;i++)
typedef long long ll;
const ll mod = 2000000;

int d[100][100];
int n;

void warshall_floyd() {
	rep(k, 0, n) {
		rep(i, 0, n) {
			rep(j, 0, n) {
				if(d[i][j]>d[i][k]+d[k][j]){
					d[i][j] = d[i][k] + d[k][j];
					d[j][i] = d[i][j];
				}
			}
		}
	}
}

int main() {
	int m;
	int s[52],a[52],b[52],c[52];
	cin >> n;
	rep(i, 0, n)cin >> s[i];
	cin >> m;
	rep(i, 0, n) {
		rep(j, 0, n) {
			if (i == j) {d[i][j] = 0; d[j][i] = 0;}
			else {d[i][j] = mod; d[j][i] = mod;}
		}
	}
	rep(i, 0, m) { 
		int a,b,c;
		cin >> a>>b>>c;
		d[a][b] = min(d[a][b],c);
		d[b][a] = d[a][b];
	}
	warshall_floyd();
	int ans = INT_MAX;
	rep(i, 1, n-1) {
		rep(j, 1, n-1) {
			if (i == j)continue;
			int cost = 0;
			cost = d[0][i] + d[i][j] + d[j][n - 1] + s[i] + s[j];
			ans = min(ans, cost);
		}
	}
	print(ans);
}
0