結果

問題 No.2805 Go to School
ユーザー reirei
提出日時 2024-07-12 21:42:00
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 246 ms / 2,000 ms
コード長 2,008 bytes
コンパイル時間 1,243 ms
コンパイル使用メモリ 119,612 KB
実行使用メモリ 27,172 KB
最終ジャッジ日時 2024-07-16 01:38:54
合計ジャッジ時間 5,902 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 79 ms
16,768 KB
testcase_05 AC 101 ms
14,436 KB
testcase_06 AC 59 ms
9,552 KB
testcase_07 AC 48 ms
9,344 KB
testcase_08 AC 82 ms
14,720 KB
testcase_09 AC 59 ms
9,452 KB
testcase_10 AC 49 ms
9,344 KB
testcase_11 AC 246 ms
21,640 KB
testcase_12 AC 129 ms
15,168 KB
testcase_13 AC 191 ms
18,876 KB
testcase_14 AC 23 ms
6,940 KB
testcase_15 AC 2 ms
6,940 KB
testcase_16 AC 2 ms
6,940 KB
testcase_17 AC 2 ms
6,940 KB
testcase_18 AC 81 ms
11,624 KB
testcase_19 AC 55 ms
9,188 KB
testcase_20 AC 136 ms
16,192 KB
testcase_21 AC 232 ms
20,308 KB
testcase_22 AC 82 ms
11,136 KB
testcase_23 AC 131 ms
15,004 KB
testcase_24 AC 134 ms
15,080 KB
testcase_25 AC 38 ms
9,224 KB
testcase_26 AC 164 ms
27,172 KB
testcase_27 AC 86 ms
16,380 KB
testcase_28 AC 8 ms
6,940 KB
testcase_29 AC 14 ms
7,680 KB
testcase_30 AC 43 ms
12,356 KB
testcase_31 AC 64 ms
10,304 KB
testcase_32 AC 116 ms
19,828 KB
testcase_33 AC 169 ms
19,668 KB
testcase_34 AC 2 ms
6,944 KB
testcase_35 AC 2 ms
6,940 KB
testcase_36 AC 59 ms
9,472 KB
testcase_37 AC 63 ms
10,240 KB
testcase_38 AC 154 ms
15,452 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;
using i8 = int8_t;
using i32 = int;
using i64 = long long;
// using i128 = __int128;
using u64 = unsigned long long;
using ll = long long;

void _main();
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  _main();
}

i64 pow(i64 j, i64 n) {
  i64 res = 1;
  while (n > 0) {
    if (n & 1)
      res *= j;
    j *= j;
    n >>= 1;
  }
  return res;
}

i64 n, m, l, s, e;
void _main() {
  cin >> n >> m >> l >> s >> e;
  vector<vector<pair<i64, i64>>> g(n);
  vector<i64> toire(l);
  for (i64 i = 0; i < m; i++) {
    i64 a, b, t;
    cin >> a >> b >> t;
    a--, b--;
    g[a].push_back({b, t});
    g[b].push_back({a, t});
  }
  for (i64 i = 0; i < l; i++) {
    cin >> toire[i];
    toire[i]--;
  }
  vector<i64> f(n, 1ll << 60);
  using el = pair<i64, i64>;
  priority_queue<el, vector<el>, greater<el>> que1;
  f[0] = 0;
  que1.push({0, 0});
  while (!que1.empty()) {
    auto [d, i] = que1.top();
    que1.pop();
    if (f[i] < d) {
      continue;
    }
    for (auto [ni, t] : g[i]) {
      if (f[ni] > f[i] + t) {
        f[ni] = f[i] + t;
        que1.push({f[ni], ni});
      }
    }
  }
  priority_queue<el, vector<el>, greater<el>> que2;
  vector<i64> b(n, 1ll << 60);
  b[n - 1] = 0;
  que2.push({0, n - 1});
  while (!que2.empty()) {
    auto [d, i] = que2.top();
    que2.pop();
    if (b[i] < d) {
      continue;
    }
    for (auto [ni, t] : g[i]) {
      if (b[ni] > b[i] + t) {
        b[ni] = b[i] + t;
        que2.push({b[ni], ni});
      }
    }
  }
  i64 ans = 1ll << 60;
  for (auto i : toire) {
    if (f[i] < s) {
      ans = min(ans, s + 1 + b[i]);
    } else if (f[i] < s + e) {
      ans = min(ans, f[i] + 1 + b[i]);
    }
  }
  if (ans == 1ll << 60) {
    cout << "-1\n";
  } else {
    cout << ans << "\n";
  }
}
0