結果

問題 No.788 トラックの移動
ユーザー risujirohrisujiroh
提出日時 2019-02-08 21:48:31
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,691 bytes
コンパイル時間 1,972 ms
コンパイル使用メモリ 178,124 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-14 03:38:52
合計ジャッジ時間 5,066 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using uint = unsigned int;
using lint = long long int;
using ulint = unsigned long long int;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;
template<class T, class U> void assign(V<T>& v, int n, const U& a) { v.assign(n, a); }
template<class T, class... Args> void assign(V<T>& v, int n, const Args&... args) { v.resize(n); for (auto&& e : v) assign(e, args...); }


struct Edge { int to, cost; };

template<class T, class Edge> V<T> dijkstra(const VV<Edge>& g, int s = 0) {
  V<T> dist(g.size(), numeric_limits<T>::max());
  using P = pair<T, int>;
  priority_queue<P, V<P>, greater<P> > pque;
  pque.emplace(dist[s] = 0, s);
  while (!pque.empty()) {
    T d; int v;
    tie(d, v) = pque.top(); pque.pop();
    if (d > dist[v]) continue;
    for (const auto& e : g[v]) {
      if (dist[e.to] <= dist[v] + e.cost) continue;
      pque.emplace(dist[e.to] = dist[v] + e.cost, e.to);
    } 
  }
  return dist;
}

int main() {
  cin.tie(nullptr); ios_base::sync_with_stdio(false);
  int n, m, l; cin >> n >> m >> l, --l;
  V<> t(n); for (int i = 0; i < n; ++i) cin >> t[i];
  VV<Edge> g(n);
  for (int i = 0; i < m; ++i) {
    int a, b, c; cin >> a >> b >> c, --a, --b;
    g[a].emplace_back(Edge{b, c});
    g[b].emplace_back(Edge{a, c});
  }
  auto dl = dijkstra<int>(g, l);
  lint res = 9e18;
  for (int v = 0; v < n; ++v) {
    auto d = dijkstra<int>(g, v);
    lint curr = 2 * inner_product(begin(t), end(t), begin(d), 0LL);
    int mx = 0;
    for (int u = 0; u < n; ++u) if (t[u] > 0) {
      mx = max(mx, d[u] - dl[u]);
    }
    curr -= mx;
    res = min(res, curr);
  }
  cout << res << '\n';
}
0