結果

問題 No.17 2つの地点に泊まりたい
ユーザー satanicsatanic
提出日時 2016-01-10 02:45:01
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 862 bytes
コンパイル時間 1,241 ms
コンパイル使用メモリ 65,628 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-19 19:44:45
合計ジャッジ時間 1,700 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

#define INF (1<<12)

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  
  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> > c(n, vector<int>(n, INF));
  for(int i=0; i<m; ++i){
    int a, b, input_c;
    cin >> a >> b >> input_c;
    c[a][b] = c[b][a] = input_c;
  }
  for(int i=0; i<n; ++i){
    for(int j=0; j<n; ++j){
      for(int k=0; k<n; ++k){
	int tmp = c[i][k]+c[k][j];
	if(c[i][j] > tmp){
	  c[i][j] = tmp;
	}
      }
    }
  }

  int result=INF;
  for(int i=1; i<n-1; ++i){
    for(int j=1; j<n-1; ++j){
      if(i==j) continue;
      int tmp = c[0][i]+s[i]+c[i][j]+s[j]+c[j][n-1];
      if(result > tmp){
	result = tmp;
      }
    }
  }

  cout << result << "\n";

  return 0;
}
0