結果

問題 No.848 なかよし旅行
ユーザー cotton_fn_cotton_fn_
提出日時 2019-07-05 22:04:47
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,115 bytes
コンパイル時間 1,454 ms
コンパイル使用メモリ 124,376 KB
実行使用メモリ 10,848 KB
最終ジャッジ日時 2024-04-16 07:21:19
合計ジャッジ時間 3,676 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 156 ms
10,848 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 60 ms
6,528 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 5 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 <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <array>
#include <set>
#include <map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <cassert>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cstdint>

using namespace std;
using i64 = int64_t;
using i32 = int32_t;
template<class T, class U> void init_n(vector<T>& v, size_t n, U x) 
{ v = vector<T>(n, x); }
template<class T> void init_n(vector<T>& v, size_t n) { init_n(v, n, T()); }
template<class T> void read_n(vector<T>& v, size_t n, size_t o = 0) 
{ v = vector<T>(n+o); for (size_t i=o; i<n+o; ++i) cin >> v[i]; }
template<class T> void read_n(T a[], size_t n, size_t o = 0)
{ for (size_t i=o; i<n+o; ++i) cin >> a[i]; }
template<class T> T gabs(const T& x) { return max(x, -x); }
#define abs gabs

template<class T>
vector<i64> djk(const T& e, i64 n, i64 s) {
  vector<i64> d(n + 1, 1e18);
  vector<bool> fix(n + 1);

  using P = pair<i64, i64>;
  priority_queue<P, vector<P>, greater<P>> pq;
  d[s] = 0;
  pq.emplace(0, s);
  while (!pq.empty()) {
    P p = pq.top(); pq.pop();
    i64 u = p.second;
    if (fix[u]) continue;
    fix[u] = true;
    for (const P& q : e[u]) {
      i64 cv = q.first, v = q.second;
      if (!fix[v] && d[u] + cv < d[v]) {
        pq.emplace(d[u] + cv, v);
        d[v] = d[u] + cv;
      }
    }
  }
  return d;
}

i64 n, m, p, q, t;
vector<vector<pair<i64, i64>>> g;
int main() {
  cin >> n >> m >> p >> q >> t;
  init_n(g, n + 1);
  for (i64 i = 0; i < m; ++i) {
    i64 a, b, c;
    cin >> a >> b >> c;
    g[a].emplace_back(c, b);
    g[b].emplace_back(c, a);
  }
  
  auto d1 = djk(g, n, 1);
  auto dp = djk(g, n, p);
  auto dq = djk(g, n, q);

  bool ok = false;
  i64 ans = 0;
  if (d1[p] + dp[q] + dq[1] <= t
      || 2 * (d1[p] + d1[q]) <= t) {
    ans = t;
    ok = true;
  }
  for (i64 u = 1; u < n; ++u) {
    i64 x = 2 * max(dp[u], dq[u]);
    if (2 * d1[u] + x <= t) {
      ans = max(ans, t - x);
      ok = true;
    }
  }

  if (!ok) ans = -1;
  cout << ans << endl;
  return 0;
}
0