結果

問題 No.17 2つの地点に泊まりたい
ユーザー ninoinuininoinui
提出日時 2020-07-22 02:37:33
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 867 bytes
コンパイル時間 2,095 ms
コンパイル使用メモリ 203,904 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-08-30 15:32:21
合計ジャッジ時間 3,559 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int main() {
  int N;
  cin >> N;
  vector<int> S(N);
  for (int i = 0; i < N; i++) cin >> S.at(i);
  int M;
  cin >> M;
  vector<vector<int>> G(N, vector<int>(N, 1e9));
  for (int a, b, c; cin >> a >> b >> c;) {
    G.at(a).at(b) = c;
    G.at(b).at(a) = c;
  }
  for (int i = 0; i < N; i++) {
    G.at(i).at(i) = 0;
  }
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      for (int k = 0; k < N; k++) {
        G.at(j).at(k) = min(G.at(j).at(k), G.at(j).at(i) + G.at(i).at(k));
      }
    }
  }
  int ans = 1e9;
  for (int i = 1; i < N - 1; i++) {
    for (int j = 1; j < N - 1; j++) {
      if (i == j) continue;
      int tmp = S.at(i) + S.at(j);
      tmp += G.at(0).at(i);
      tmp += G.at(i).at(j);
      tmp += G.at(j).at(N - 1);
      ans = min(ans, tmp);
    }
  }
  cout << ans << "\n";
}
0