結果

問題 No.17 2つの地点に泊まりたい
ユーザー rokahikou1rokahikou1
提出日時 2019-09-09 14:37:21
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 3 ms / 5,000 ms
コード長 905 bytes
コンパイル時間 619 ms
コンパイル使用メモリ 80,824 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-10 21:03:31
合計ジャッジ時間 2,218 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <string>
#include <iomanip>
#include <map>
#include <set>
#include <cmath>
#include <cstdio>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define FOR(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define All(v) (v).begin(),(v).end()
typedef long long ll;

int main(){
    int N;
    cin >> N;
    vector<int> S(N);
    rep(i,N)cin >> S[i];
    int M;cin >> M;
    vector<vector<int> > d(N,vector<int>(N,1<<28));
    rep(i,M){
        int a,b,c;
        cin >> a >> b >> c;
        d[a][b]=c;
        d[b][a]=c;
    }

    rep(k,N)rep(i,N)rep(j,N)d[i][j]=min(d[i][j],d[i][k]+d[k][j]);

    int res = 1<<28;
    for(int x=1;x<N-1;x++)for(int y=1;y<N-1;y++){
        if(x==y)continue;
        res = min(res,S[x]+S[y]+d[0][x]+d[x][y]+d[y][N-1]);
    }

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