結果

問題 No.17 2つの地点に泊まりたい
ユーザー Kutimoti_TKutimoti_T
提出日時 2017-12-18 08:00:46
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 1,057 bytes
コンパイル時間 599 ms
コンパイル使用メモリ 68,184 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-23 02:21:16
合計ジャッジ時間 1,256 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
using namespace std;

#define FOR(i, s, e) for (int i = (s); i <= (e); i++)
#define INF 10000000;

int N;
int stay[50];

int M;


int dp[55][55];

int main()
{
    FOR(i, 0, 54)
    {
        FOR(j, 0, 54)
        {
            dp[i][j] = INF
        }
    }
    cin >> N;
    FOR(i, 0, N - 1)
    {
        cin >> stay[i];
    }

    cin >> M;
    int a, b, c;
    FOR(i, 0, M - 1)
    {
        cin >> a >> b >> c;
        dp[a][b] = c;
        dp[b][a] = c;
    }

    FOR(i,0,N - 1)
    {
        FOR(j,0,N - 1)
        {
            FOR(k,0,N - 1)
            {
                dp[j][k] = min(dp[j][k],dp[j][i] + dp[i][k]);
            }
        }
    }

    int res = INF;

    FOR(i,1,N - 2)
    {
        FOR(j,1,N - 2)
        {
            if(i != j)
            {
                res = min(res,dp[0][i] + stay[i] + dp[i][j] + stay[j] + dp[j][N - 1]);
            }
        }
    }

    cout << res << endl;
    return 0;
}
0