結果

問題 No.17 2つの地点に泊まりたい
ユーザー zaichuzaichu
提出日時 2017-11-19 22:49:01
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,141 bytes
コンパイル時間 1,659 ms
コンパイル使用メモリ 169,968 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-08-17 06:22:52
合計ジャッジ時間 2,687 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

template <typename T>
T gcd(T x, T y)
{
    if (y == 0)
        return x;
    return gcd(y, x % y);
}

template <typename T>
T lcm(T x, T y)
{
    if (x == 0 || y == 0)
        return 0;
    return x / gcd(x, y) * y;
}

int main()
{
    int N;
    cin >> N;
    vector<int> S(N);
    for (int i = 0; i < N; i++)
        cin >> S[i];

    int M;
    cin >> M;
    vector<vector<int>> vv(N, vector<int>(N, INT_MAX));
    for (int i = 0; i < M; i++)
    {
        int A, B, C;
        cin >> A >> B >> C;
        vv[A][B] = vv[B][A] = C;
    }
    for (int i = 0; i < N; i++)
        vv[i][i] = 0;

    for (int k = 0; k < N; k++)
        for (int i = 0; i < N; i++)
            for (int j = 0; j < N; j++)
                if (vv[i][j] > vv[i][k] + vv[k][j])
                    vv[i][j] = vv[i][k] + vv[k][j];

    int ans = INT_MAX;
    for (int i = 1; i < N - 1; i++)
    {
        for (int j = 1; j < N - 1; j++)
        {
            if (i == j)
                continue;
            ans = min(ans, vv[0][i] + vv[i][j] + vv[j][N - 1] + S[i] + S[j]);
        }
    }
    cout << ans << endl;
}
0