結果

問題 No.17 2つの地点に泊まりたい
ユーザー koba-e964koba-e964
提出日時 2015-05-11 21:49:34
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,455 bytes
コンパイル時間 593 ms
コンパイル使用メモリ 87,980 KB
実行使用メモリ 4,500 KB
最終ジャッジ日時 2023-09-20 02:53:05
合計ジャッジ時間 1,678 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 WA -
testcase_03 AC 1 ms
4,376 KB
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 AC 2 ms
4,376 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 1 ms
4,376 KB
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 -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)

using namespace std;
typedef long long int ll;
typedef vector<int> VI;
typedef pair<int, int> PI;
const double EPS=1e-9;


const int N = 55;
const int inf = 123456789;
int s[N];
int dist[N][N];
const int DEBUG = 0;

int main(void){
  int n;
  cin >> n;
  REP(i, 0, n) {
    cin >> s[i];
  }
  REP(i, 0, n) {
    REP(j, 0, n) {
      dist[i][j] = inf;
    }
    dist[i][i] = 0;
  }
  int m;
  cin >> m;
  REP(i, 0, m) {
    int a, b, c;
    cin >> a >> b >> c;
    dist[a][b] = c + s[a];
    dist[b][a] = c + s[b];
  }
  REP(k, 0, n) {
    REP(i, 0, n) {
      REP(j, 0, n) {
	dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
      }
    }
  }
  if (DEBUG) {
    REP(i, 0, n) {
      REP(j, 0, n) {
	cout << "dist[" << i << "][" << j << "]=" << dist[i][j] << endl;
      }
    }
  }
  m = inf;
  REP(i, 1, n - 1) {
    REP(j, 1, n - 1) {
      if (i == j) {
        continue;
      }
      m = min(m, dist[0][i] + dist[i][j] + dist[j][n - 1]);
    }
  }
  cout << m << endl;
}
0