結果

問題 No.17 2つの地点に泊まりたい
ユーザー fantasiabaeticafantasiabaetica
提出日時 2018-08-09 16:32:17
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 914 bytes
コンパイル時間 434 ms
コンパイル使用メモリ 55,024 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-23 04:33:13
合計ジャッジ時間 1,127 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 1 ms
5,376 KB
testcase_13 AC 1 ms
5,376 KB
testcase_14 AC 1 ms
5,376 KB
testcase_15 AC 2 ms
5,376 KB
testcase_16 AC 1 ms
5,376 KB
testcase_17 AC 1 ms
5,376 KB
testcase_18 AC 1 ms
5,376 KB
testcase_19 AC 2 ms
5,376 KB
testcase_20 AC 2 ms
5,376 KB
testcase_21 AC 1 ms
5,376 KB
testcase_22 AC 1 ms
5,376 KB
testcase_23 AC 2 ms
5,376 KB
testcase_24 AC 2 ms
5,376 KB
testcase_25 AC 1 ms
5,376 KB
testcase_26 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#define FOR(i,a,b) for(int i=(a); i<(b); i++)
using namespace std;
const int INF = 1<<27;

int N, M;
int stay_cost[50];
int from, to, cost;
int wf[50][50];

int main(){
    cin >> N;
    FOR(i, 0, N){
        cin >> stay_cost[i]; 
    }
    cin >> M;
    // Warshall–Floyd
    FOR(i, 0, N) {
        FOR(j, 0, N) {
            if (i == j) wf[i][j] = 0;
            else wf[i][j] = INF;
        }
    }
    FOR(i, 0, M){
        cin >> from >> to >> cost; 
        // 無向グラフ
        wf[from][to] = cost;
        wf[to][from] = cost;
    }
    FOR(i, 0, N) FOR(f, 0, N) FOR(t, 0, N) wf[f][t] = min(wf[f][t], wf[f][i] + wf[i][t]);

    // 全探索
    int ans = INF;
    FOR(i, 1, N - 1){
        FOR(j, 1, N - 1){
            if (i == j) continue;
            ans = min(ans, wf[0][i] + stay_cost[i] + wf[i][j] + stay_cost[j] + wf[j][N-1]);
        }
    }

    cout << ans << endl;
}
0