結果

問題 No.17 2つの地点に泊まりたい
ユーザー furonfuron
提出日時 2023-05-31 12:01:35
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,699 bytes
コンパイル時間 1,310 ms
コンパイル使用メモリ 128,616 KB
実行使用メモリ 5,332 KB
最終ジャッジ日時 2023-08-28 01:27:23
合計ジャッジ時間 3,022 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <string>
#include <queue>
#include <map>
#include <bitset>
#include <set>
#include <stack>
#include <numeric>
#include <unordered_map>
#include <random>

using namespace std;

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vd = vector<double>;
using vs = vector<string>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pdd = pair<double, double>;
using vpii = vector<pii>;
using vpll = vector<pll>;
using vpdd = vector<pdd>;
const int inf = (1 << 30) - 1;
const ll INF = 1LL << 60;
//const int MOD = 1000000007;
const int MOD = 998244353;

void warshall_floyd(vvi& d, int V) {
	for (int k = 0; k < V; k++)
		for (int i = 0; i < V; i++)
			for (int j = 0; j < V; j++)
				d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
}

int main() {
	int n;
	cin >> n;
	vi s(n);
	for (int i = 0; i < n; i++) {
		cin >> s[i];
	}
	int m;
	cin >> m;
	vi a(m), b(m), c(m);
	for (int i = 0; i < m; i++) {
		cin >> a[i] >> b[i] >> c[i];
	}
	vvi g(n, vi(n, inf));
	for (int i = 0; i < n; i++) g[i][i] = 0;
	
	for (int i = 0; i < m; i++) {
		g[a[i]][b[i]] = g[b[i]][a[i]] = c[i];
	}
	warshall_floyd(g, n);

	int ans = inf;
	// 滞在先を全探索する
	// 0からi に向かい、i に滞在した後 jに滞在し n-1 へ向かう
	for (int i = 1; i <= n - 2; i++) {
		int cost1 = g[0][i] + s[i];
		for (int j = 1; j <= n - 2; j++) {
			if (i == j) continue;
			ans = min(ans, cost1 + g[i][j] + s[j] + g[j][n - 1]);
		}
	}
	cout << ans << endl;
	
	return 0;
}
0