結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
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 -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: 関数 ‘int main()’ 内:
main.cpp:23:20: 警告: ‘N’ is used uninitialized [-Wuninitialized]
   23 |     vector<int> S(N);
      |                    ^
main.cpp:22:9: 備考: ‘N’ はここで定義されています
   22 |     int N;
      |         ^
main.cpp:29:23: 警告: ‘M’ may be used uninitialized [-Wmaybe-uninitialized]
   29 |     for (int i = 0; i < M; i++)
      |                     ~~^~~
main.cpp:27:9: 備考: ‘M’ はここで定義されています
   27 |     int M;
      |         ^

ソースコード

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;
    vector<int> S(N);
    for (int i = 0; i < N; i++)
        cin >> S[i];

    int 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