結果

問題 No.788 トラックの移動
ユーザー simansiman
提出日時 2023-07-06 23:13:30
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,917 bytes
コンパイル時間 5,008 ms
コンパイル使用メモリ 108,520 KB
実行使用メモリ 19,496 KB
最終ジャッジ日時 2023-09-28 00:15:51
合計ジャッジ時間 9,451 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <cassert>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <climits>
#include <map>
#include <queue>
#include <set>
#include <cstring>
#include <vector>

using namespace std;
typedef long long ll;

struct Node {
  int v;
  int cost;

  Node(int v = -1, int cost = -1) {
    this->v = v;
    this->cost = cost;
  }

  bool operator>(const Node &n) const {
    return cost > n.cost;
  }
};

struct Edge {
  int to;
  int cost;

  Edge(int to, int cost) {
    this->to = to;
    this->cost = cost;
  }
};

int g_cost[2010][2010];

int main() {
  int N, M, L;
  cin >> N >> M >> L;

  int T[N];
  for (int i = 0; i < N; ++i) {
    cin >> T[i];
  }

  memset(g_cost, 0, sizeof(g_cost));

  vector<Edge> G[N + 1];
  for (int i = 0; i < M; ++i) {
    int a, b, c;
    cin >> a >> b >> c;

    G[a].push_back(Edge(b, c));
    G[b].push_back(Edge(a, c));
  }

  for (int v = 1; v <= N; ++v) {
    priority_queue <Node, vector<Node>, greater<Node>> pque;
    bool visited[N + 1];
    memset(visited, false, sizeof(visited));

    pque.push(Node(v, 0));
    while (not pque.empty()) {
      Node node = pque.top();
      pque.pop();

      if (visited[node.v]) continue;
      visited[node.v] = true;

      g_cost[v][node.v] = node.cost;

      for (Edge &e : G[node.v]) {
        int n_cost = node.cost + e.cost;
        pque.push(Node(e.to, n_cost));
      }
    }
  }

  int ans = INT_MAX;

  for (int v = 1; v <= N; ++v) {
    int base_cost = 0;

    for (int u = 1; u <= N; ++u) {
      base_cost += T[u - 1] * (2 * g_cost[u][v]);
    }

    int min_cost = INT_MAX;

    for (int u = 1; u <= N; ++u) {
      if (T[u - 1] == 0) continue;

      int new_cost = base_cost;
      new_cost -= 2 * g_cost[u][v];
      new_cost += g_cost[L][u] + g_cost[u][v];

      min_cost = min(min_cost, new_cost);
    }

    ans = min(ans, min_cost);
  }

  cout << ans << endl;

  return 0;
}
0