結果
| 問題 |
No.17 2つの地点に泊まりたい
|
| コンテスト | |
| ユーザー |
commy
|
| 提出日時 | 2018-08-12 21:51:47 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 3 ms / 5,000 ms |
| コード長 | 1,243 bytes |
| コンパイル時間 | 640 ms |
| コンパイル使用メモリ | 74,880 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-10-15 04:08:58 |
| 合計ジャッジ時間 | 1,404 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 27 |
ソースコード
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
#define dump(val) cerr << __LINE__ << ":\t" << #val << " = " << (val) << endl
using namespace std;
typedef long long int lli;
template<typename T>
vector<T> make_v(size_t a, T b) {
return vector<T>(a, b);
}
template<typename... Ts>
auto make_v(size_t a, Ts... ts) {
return vector<decltype(make_v(ts...))>(a, make_v(ts...));
}
int main() {
int N;
cin >> N;
vector<lli> S(N);
REP(i, 0, N) {
cin >> S[i];
}
int M;
cin >> M;
const lli inf = 1LL << 50;
auto Cost = make_v(N, N, inf);
REP(i, 0, M) {
lli A, B, C;
cin >> A >> B >> C;
Cost[A][B] = min(Cost[A][B], C);
Cost[B][A] = min(Cost[B][A], C);
}
REP(k, 0, N) {
REP(i, 0, N) {
REP(j, 0, N) {
Cost[i][j] = min(Cost[i][j], Cost[i][k] + Cost[k][j]);
}
}
}
lli ans = inf;
REP(i, 1, N - 1) {
REP(j, 1, N - 1) {
if (i == j) continue;
ans = min(ans, S[i] + S[j] + Cost[0][i] + Cost[i][j] + Cost[j][N - 1]);
}
}
cout << ans << endl;
return 0;
}
commy