結果

問題 No.788 トラックの移動
ユーザー ei1333333ei1333333
提出日時 2019-02-08 21:41:50
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,098 bytes
コンパイル時間 1,918 ms
コンパイル使用メモリ 202,336 KB
実行使用メモリ 45,868 KB
最終ジャッジ日時 2023-09-14 03:38:32
合計ジャッジ時間 8,249 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 -- -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

using int64 = long long;
const int64 INF = 1LL << 60;


int main() {
  int N, M, L;
  int64 v[2000][2000];
  fill_n(*v, 2000 * 2000, INF);
  cin >> N >> M >> L;
  --L;
  for(int i = 0; i < N; i++) v[i][i] = 0;
  vector< pair< int, int > > ex;
  for(int i = 0; i < N; i++) {
    int p;
    cin >> p;
    if(p > 0) ex.emplace_back(i, p);
  }
  for(int i = 0; i < M; i++) {
    int a, b, c;
    cin >> a >> b >> c;
    --a, --b;
    v[a][b] = c;
    v[b][a] = c;
  }
  for(int k = 0; k < N; k++) {
    for(int i = 0; i < N; i++) {
      for(int j = 0; j < N; j++) {
        v[i][j] = min(v[i][j], v[i][k] + v[k][j]);
      }
    }
  }
  int64 ret = INF;
  for(int i = 0; i < N; i++) {
    int64 cost = 0, pv = 0;
    bool exist = false;
    for(auto e : ex) {
      if(e.first == L) exist = true;
      cost += v[i][e.first] * 2 * e.second;
    }
    if(exist) {
      cost -= v[i][L];
    } else {
      for(auto e : ex) {
        pv = max(pv, v[i][e.first] - v[L][e.first]);
      }
    }

    ret = min(ret, cost - pv);
  }
  cout << ret << endl;
}

0