結果

問題 No.17 2つの地点に泊まりたい
ユーザー monnumonnu
提出日時 2021-07-14 01:42:10
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 3 ms / 5,000 ms
コード長 934 bytes
コンパイル時間 1,762 ms
コンパイル使用メモリ 170,188 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-15 21:06:40
合計ジャッジ時間 2,687 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
//#include <atcoder/all>
//using namespace atcoder;
using ll=long long;
using Graph=vector<vector<int>>;
#define MAX 1000000
#define MOD 1000000009
//#define MOD 998244353
//#define INF 1000000000
#define INF 1000000000000000000

int main(){
  int N;
  cin>>N;
  vector<ll> S(N);
  for(int i=0;i<N;i++){
    cin>>S[i];
  }
  vector<vector<ll>> dist(N,vector<ll>(N,INF));
  int M;
  cin>>M;
  for(int i=0;i<M;i++){
    int a,b;
    ll c;
    cin>>a>>b>>c;
    dist[a][b]=min(dist[a][b],c);
    dist[b][a]=min(dist[b][a],c);
  }
  for(int k=0;k<N;k++){
    for(int i=0;i<N;i++){
      for(int j=0;j<N;j++){
        dist[i][j]=min(dist[i][j],dist[i][k]+dist[k][j]);
      }
    }
  }

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