結果

問題 No.848 なかよし旅行
ユーザー 0w10w1
提出日時 2019-07-05 22:16:18
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,318 bytes
コンパイル時間 2,450 ms
コンパイル使用メモリ 207,564 KB
実行使用メモリ 13,900 KB
最終ジャッジ日時 2024-04-16 07:33:19
合計ジャッジ時間 4,216 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 101 ms
13,900 KB
testcase_01 AC 2 ms
6,944 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 31 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 4 ms
6,944 KB
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 2 ms
6,940 KB
testcase_25 WA -
testcase_26 AC 2 ms
6,944 KB
testcase_27 AC 2 ms
6,940 KB
testcase_28 AC 2 ms
6,940 KB
testcase_29 AC 2 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

vector<long long> dijkstra(vector<vector<pair<long long, int>>> E, int S) {
  const long long INF = 1LL << 60;
  int n = E.size();
  vector<long long> dis(n, INF);
  priority_queue<pair<long long, int>> pq;
  pq.emplace(dis[S] = 0, S);
  while (pq.size()) {
    int d, u;
    tie(d, u) = pq.top();
    d *= -1;
    pq.pop();
    if (d != dis[u]) continue;
    for (auto e : E[u]) {
      long long w;
      int v;
      tie(w, v) = e;
      if (dis[v] <= dis[u] + w) continue;
      dis[v] = dis[u] + w;
      pq.emplace(-dis[v], v);
    }
  }
  return dis;
}

signed main() {
  ios::sync_with_stdio(false);

  int N, M, P, Q, T;
  cin >> N >> M >> P >> Q >> T;
  --P;
  --Q;

  vector<vector<pair<long long, int>>> G(N);
  for (int i = 0; i < M; ++i) {
    int u, v, w;
    cin >> u >> v >> w;
    G[u - 1].emplace_back(w, v - 1);
    G[v - 1].emplace_back(w, u - 1);
  }

  vector<long long> pdis = dijkstra(G, P);
  vector<long long> qdis = dijkstra(G, Q);
  vector<long long> odis = dijkstra(G, 0);

  int ans = -1;
  for (int i = 0; i < N; ++i) {
    if (1LL * T < 2LL * (odis[i] + max(pdis[i], qdis[i]))) continue;
    ans = max<int>(ans, T - 2LL * max(pdis[i], qdis[i]));
  }
  if (odis[P] + pdis[Q] + qdis[0] <= T) ans = T;

  cout << ans << endl;

  return 0;
}
0