結果

問題 No.848 なかよし旅行
ユーザー risujirohrisujiroh
提出日時 2019-07-05 21:55:37
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,291 bytes
コンパイル時間 2,150 ms
コンパイル使用メモリ 175,364 KB
実行使用メモリ 8,780 KB
最終ジャッジ日時 2024-04-16 07:16:38
合計ジャッジ時間 3,890 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using lint = long long;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;

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[v] + e.cost < dist[e.to]) {
      pque.emplace(dist[e.to] = dist[v] + e.cost, e.to);
    } 
  }
  return dist;
}

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  int n, m, p, q, t; cin >> n >> m >> p >> q >> t, --p, --q;
  VV<Edge> g(n);
  while (m--) {
    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 d0 = dijkstra<lint>(g, 0);
  auto dp = dijkstra<lint>(g, p);
  auto dq = dijkstra<lint>(g, q);
  lint res = -1;
  for (int v = 0; v < n; ++v) {
    if (2 * (d0[v] + max(dp[v], dq[v])) > t) continue;
    res = max(res, t - 2 * max(dp[v], dq[v]));
  }
  if (d0[p] + dp[q] + dq[0] <= t) res = t;
  cout << res << '\n';
}
0