結果

問題 No.848 なかよし旅行
ユーザー ninjaninja
提出日時 2019-07-05 22:18:06
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,960 bytes
コンパイル時間 2,002 ms
コンパイル使用メモリ 177,568 KB
実行使用メモリ 10,044 KB
最終ジャッジ日時 2024-04-16 07:33:46
合計ジャッジ時間 3,707 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 64 ms
9,240 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 44 ms
7,280 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 ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;

ll INF = 1010101010101010LL;
vector<vector<pair<int, ll>>> ps;

struct N {
  ll i, d;

  N(int i, ll d) : i(i), d(d) {}
};

bool operator<(const N &l, const N &r) {
  return l.d > r.d;
}

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  ll n, m, p, q, t;
  cin >> n >> m >> p >> q >> t;
  p--;
  q--;

  vector<ll> fromp(n, INF), fromq(n, INF), from1(n, INF);
  ps.resize(n);

  for (int i = 0; i < m; i++) {
    ll a, b, c;
    cin >> a >> b >> c;
    a--;
    b--;
    ps[a].emplace_back(b, c);
    ps[b].emplace_back(a, c);
  }

  priority_queue<N> queue;
  queue.emplace(p, 0);
  while (queue.size()) {
    auto v = queue.top();
    queue.pop();
    if (fromp[v.i] < INF) continue;
    fromp[v.i] = v.d;
    for (auto &path : ps[v.i]) {
      if (fromp[path.first] < INF) continue;
      queue.emplace(path.first, v.d + path.second);
    }
  }

  queue.emplace(q, 0);
  while (queue.size()) {
    auto v = queue.top();
    queue.pop();
    if (fromq[v.i] < INF) continue;
    fromq[v.i] = v.d;
    for (auto &path : ps[v.i]) {
      if (fromq[path.first] < INF) continue;
      queue.emplace(path.first, v.d + path.second);
    }
  }

  queue.emplace(0, 0);
  while (queue.size()) {
    auto v = queue.top();
    queue.pop();
    if (from1[v.i] < INF) continue;
    from1[v.i] = v.d;
    for (auto &path : ps[v.i]) {
      if (from1[path.first] < INF) continue;
      queue.emplace(path.first, v.d + path.second);
    }
  }

  ll ans = -1;
  for (int i = 0; i < n; i++) {
    ll pcost = fromp[i] * 2;
    ll qcost = fromq[i] * 2;
    ll cost = from1[i] * 2;
    if (max(pcost, qcost) + cost <= t) {
      ans = max(ans, t - max(pcost, qcost));
    }
  }
  if (from1[p] + from1[q] + fromp[q] <= t) {
    ans = t;
  }

  cout << ans << endl;

  return 0;
}
0