結果

問題 No.17 2つの地点に泊まりたい
ユーザー TwizzTwizz
提出日時 2017-05-15 11:10:28
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 864 bytes
コンパイル時間 2,045 ms
コンパイル使用メモリ 145,020 KB
実行使用メモリ 4,484 KB
最終ジャッジ日時 2023-10-14 13:10:48
合計ジャッジ時間 4,311 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

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

ソースコード

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 = 20000000;

int d[52][52];
int n;

void warshall_floyd() {
	rep(k, 0, n) {
		rep(i, 0, n) {
			rep(j, 0, n) {
				d[i][j] = min(d[i][j], d[i][k] + d[k][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, m)cin >> a[i] >> b[i] >> c[i];
	rep(i, 0, m) {
		rep(j, 0, m) {
			if (i == j)d[i][j] = 0;
			else d[i][j] = mod;
		}
	}
	rep(i, 0, m) { d[a[i]][b[i]] = c[i]; d[b[i]][a[i]] = c[i]; }
	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