結果

問題 No.17 2つの地点に泊まりたい
ユーザー PachicobuePachicobue
提出日時 2017-03-14 05:18:59
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,980 bytes
コンパイル時間 406 ms
コンパイル使用メモリ 61,256 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-12 12:18:41
合計ジャッジ時間 2,345 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <cassert>
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i <= (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)

#define pb push_back
#define mp make_pair
#define fst first
#define snd second
#define show(x) cout << #x << " = " << x << endl
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define pii pair<int, int>
#define vi vector<int>

using namespace std;
template <class S, class T>
ostream& operator<<(ostream& o, const pair<S, T>& p)
{
    return o << "(" << p.first << "," << p.second << ")";
}
template <class T>
ostream& operator<<(ostream& o, const vector<T>& vc)
{
    o << "sz = " << vc.size() << endl
      << "[";
    for (const T& v : vc)
        o << v << ",";
    o << "]";
    return o;
}
typedef long long ll;

#define NMAX 50
#define MMAX 1225
int N;
int S[NMAX];
int M;
int A[MMAX];
int B[MMAX];
int C[MMAX];

int d[NMAX][NMAX];

#define CINF 100000

int main()
{
    cin >> N;
    rep(i, N)
    {
        rep(j, N)
        {
            d[i][j] = CINF;
        }
    }
    rep(i, N)
    {
        cin >> S[i];
    }
    cin >> M;
    rep(i, M)
    {
        cin >> A[i] >> B[i] >> C[i];
        d[A[i]][B[i]] = C[i];
        d[B[i]][A[i]] = C[i];
    }

    rep(i, N)
    {
        rep(j, N)
        {
            rep(k, N)
            {
                if (d[i][j] > d[i][k] + d[k][j]) {
                    d[i][j] = d[i][k] + d[k][j];
                }
            }
        }
    }


    int cmin = CINF * 5;
    for (int i = 1; i < N - 1; i++) {
        for (int j = 1; j < N - 1; j++) {
            if (i == j) {
                continue;
            }
            chmin(cmin, d[0][i] + d[i][j] + d[j][N - 1] + S[i] + S[j]);
        }
    }
    cout << cmin << endl;

    return 0;
}
0