結果
| 問題 | No.17 2つの地点に泊まりたい | 
| コンテスト | |
| ユーザー |  ふーらくたる | 
| 提出日時 | 2016-06-24 09:47:44 | 
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 2 ms / 5,000 ms | 
| コード長 | 1,261 bytes | 
| コンパイル時間 | 509 ms | 
| コンパイル使用メモリ | 55,004 KB | 
| 実行使用メモリ | 5,248 KB | 
| 最終ジャッジ日時 | 2024-10-15 01:34:45 | 
| 合計ジャッジ時間 | 1,162 ms | 
| ジャッジサーバーID (参考情報) | judge2 / judge4 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 27 | 
ソースコード
#include <iostream>
using namespace std;
const int kINF = 1 << 25;
const int kMAX_N = 60;
const int kMAX_M = kMAX_N * (kMAX_N - 1) / 2;
int N, M;
int S[kMAX_N];
int A[kMAX_M], B[kMAX_M], C[kMAX_M];
int cost[kMAX_N][kMAX_N];
void Solve() {
    fill((int* )cost, (int* )(cost + kMAX_N), kINF);
    for (int i = 0; i < N; i++) {
        cost[i][i] = 0;
    }
    for (int i = 0; i < M; i++) {
        cost[A[i]][B[i]] = cost[B[i]][A[i]] = C[i];
    }
    for (int k = 0; k < N; k++) {
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < N; j++) {
                cost[i][j] = min(cost[i][j], cost[i][k] + cost[k][j]);
            }
        }
    }
    int answer = kINF;
    for (int node1 = 1; node1 < N - 1; node1++) {
        for (int node2 = 1; node2 < N - 1; node2++) {
            if (node1 == node2) continue;
            answer = min(answer, cost[0][node1] + cost[node1][node2] + cost[node2][N - 1] + S[node1] + S[node2]);
        }
    }
    cout << answer << endl;
}
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N;
    for (int i = 0; i < N; i++) {
        cin >> S[i];
    }
    cin >> M;
    for (int i = 0; i < M; i++) {
        cin >> A[i] >> B[i] >> C[i];
    }
    Solve();
    return 0;
}
            
            
            
        