結果

問題 No.848 なかよし旅行
ユーザー ikdikd
提出日時 2019-07-05 23:01:59
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,405 bytes
コンパイル時間 908 ms
コンパイル使用メモリ 88,744 KB
実行使用メモリ 14,028 KB
最終ジャッジ日時 2024-04-16 07:59:19
合計ジャッジ時間 4,517 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <tuple>

using namespace std;
struct Edge{
  int to;
  int64_t cost;
  Edge(int to, int64_t cost): to(to), cost(cost) {}
};

const int64_t inf = 1e18;
vector<int64_t> dijkstra(vector<vector<Edge>> g, int s) {
  int n = g.size();
  vector<int64_t> d(n, inf);
  d[s] = 0;
  priority_queue<pair<int64_t, int>> q;
  q.emplace(0, s);
  while (q.size() > 0) {
    int64_t dist;
    int v;
    tie(dist, v) = q.top();
    q.pop();
    dist *= -1;
    for (const auto &e: g[v]) {
      if (dist + e.cost < d[e.to]) {
        d[e.to] = dist + e.cost;
        q.emplace(d[e.to] * (-1), e.to);
      }
    }
  }
  return d;
}

int main() {
  
  int n, m, p, q;
  int64_t t;
  cin >> n >> m >> p >> q >> t;
  p--;
  q--;
  vector<vector<Edge>> g(n);
  for (int i = 0; i < m; i++) {
    int a, b, c;
    cin >> a >> b >> c;
    a--;
    b--;
    g[a].emplace_back(b, c);
    g[b].emplace_back(a, c);
  }

  auto d0 = dijkstra(g, 0),
       dp = dijkstra(g, p),
       dq = dijkstra(g, q);
  int64_t ans = -1;
  for (int v = 0; v < n; v++) {
    auto time = t - d0[v] * 2 - max(dp[v], dq[v]) * 2;
    if (time < 0) continue;
    ans = max(ans, d0[v] * 2 + time);
    if ((d0[v] + dp[v] + dq[v]) * 2 <= t) {
      ans = max(ans, t);
    }
    // cout << v << " " << d0[v] * 2 + time << endl;
  } 

  cout << ans << endl;
  return 0;
}
0