結果

問題 No.17 2つの地点に泊まりたい
ユーザー simansiman
提出日時 2016-03-22 02:25:22
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 3 ms / 5,000 ms
コード長 1,336 bytes
コンパイル時間 636 ms
コンパイル使用メモリ 74,100 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-23 02:12:32
合計ジャッジ時間 1,375 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <limits.h>
#include <time.h>
#include <string>
#include <string.h>
#include <sstream>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <stack>
#include <queue>

using namespace std;

typedef long long ll;

const int MAX_N = 50;
const int INF = 999999;

int dist[MAX_N][MAX_N];
int stayCost[MAX_N];

void init(){
  for(int i = 0; i < MAX_N; i++){
    for(int j = 0; j < MAX_N; j++){
      dist[i][j] = INF;
    }
  }
}

int n;

void warshall_floyd() {
  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]);
      }
    }
  }
}

int main(){
  init();

  cin >> n;

  for(int i = 0; i < n; i++){
    cin >> stayCost[i];
    dist[i][i] = 0;
  }

  int m;
  cin >> m;

  int from, to, cost;
  for(int i = 0; i < m; i++){
    cin >> from >> to >> cost;
    dist[from][to] = cost;
    dist[to][from] = cost;
  }

  warshall_floyd();

  int minCost = INT_MAX;

  for(int i = 1; i < n-1; i++){
    for(int j = 1; j < n-1; j++){
      if(i == j) continue;
      int cost = dist[0][i] + stayCost[i] + dist[i][j] + stayCost[j] + dist[j][n-1];

      minCost = min(minCost, cost);
    }
  }

  cout << minCost << endl;

  return 0;
}
0