結果
| 問題 | No.17 2つの地点に泊まりたい | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2019-12-17 15:27:30 | 
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 2 ms / 5,000 ms | 
| コード長 | 1,102 bytes | 
| コンパイル時間 | 2,699 ms | 
| コンパイル使用メモリ | 163,556 KB | 
| 実行使用メモリ | 5,376 KB | 
| 最終ジャッジ日時 | 2024-07-02 21:26:40 | 
| 合計ジャッジ時間 | 3,620 ms | 
| ジャッジサーバーID (参考情報) | judge5 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 27 | 
ソースコード
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)n; ++i)
#define FOR(i, a, b) for(int i = a; i < (int)b; ++i)
#define rrep(i, n) for(int i = ((int)n - 1); i >= 0; --i)
typedef long long ll;
typedef long double ld;
const int Inf = 1e9;
const double EPS = 1e-9;
const int MOD = 1e9 + 7;
int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(0);
    int n;
    cin >> n;
    vector<int> s(n);
    rep (i, n) cin >> s[i];
    int m;
    cin >> m;
    vector<vector<ll> > g(n, vector<ll>(n, Inf));
    rep (i, n) g[i][i] = 0;
    rep (i, m) {
        int a, b, c;
        cin >> a >> b >> c;
        g[a][b] = g[b][a] = c;
    }
    rep (k, n) {
        rep (i, n) {
            rep (j, n) g[i][j] = min(g[i][j], g[i][k] + g[k][j]);
        }
    }
    ll res = Inf;
    FOR (i, 1, n - 1) {
        FOR (j, 1, n - 1) {
            if (i == j) continue;
            ll tmp = 0;
            tmp += s[i] + s[j];
            tmp += g[0][i] + g[i][j] + g[j][n - 1];
            res = min(res, tmp);
        }
    }
    cout << res << endl;
    
    return 0;
}
            
            
            
        