結果

問題 No.17 2つの地点に泊まりたい
コンテスト
ユーザー himueu
提出日時 2026-10-16 14:15:47
言語 C++23(gcc16)
(gcc 16.2.0 + boost 1.92.0 + ACL)
コンパイル:
g++-16 -O2 -lm -std=c++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 2 ms / 5,000 ms
+ 461µs
コード長 930 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 2,010 ms
コンパイル使用メモリ 182,540 KB
実行使用メモリ 9,884 KB
最終ジャッジ日時 2026-10-16 14:15:56
合計ジャッジ時間 4,282 ms
ジャッジサーバーID
(参考情報)
judge4_0 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 28
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <algorithm>
#include <iostream>
#include <vector>

int main() {
    using namespace std;
    int n;
    cin >> n;
    vector<int> s(n);
    for (auto &e : s) { cin >> e; }

    constexpr int INF = 1e6;
    vector dist(n, vector<int>(n, INF));
    for (int i = 0; i < n; i++) { dist[i][i] = 0; }
    int m;
    cin >> m;
    while (m--) {
        int a, b, c;
        cin >> a >> b >> c;
        dist[a][b] = c;
        dist[b][a] = c;
    }

    for (int k = 0; k < n; k++) {
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
            }
        }
    }

    int ans = INF;
    for (int i = 1; i < n - 1; i++) {
        for (int j = 1; j < n - 1; j++) {
            if (i == j) { continue; }
            ans = min(ans, dist[0][i] + s[i] + dist[i][j] + s[j] + dist[j][n - 1]);
        }
    }
    cout << ans << endl;
}
0