結果

問題 No.2805 Go to School
ユーザー tnakao0123tnakao0123
提出日時 2024-07-15 15:08:49
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 220 ms / 2,000 ms
コード長 1,451 bytes
コンパイル時間 740 ms
コンパイル使用メモリ 63,104 KB
実行使用メモリ 21,844 KB
最終ジャッジ日時 2024-07-16 01:43:08
合計ジャッジ時間 4,909 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
7,936 KB
testcase_01 AC 4 ms
7,808 KB
testcase_02 AC 5 ms
7,808 KB
testcase_03 AC 5 ms
7,936 KB
testcase_04 AC 78 ms
15,104 KB
testcase_05 AC 93 ms
13,600 KB
testcase_06 AC 54 ms
11,196 KB
testcase_07 AC 46 ms
10,904 KB
testcase_08 AC 76 ms
13,620 KB
testcase_09 AC 55 ms
11,256 KB
testcase_10 AC 48 ms
10,832 KB
testcase_11 AC 220 ms
18,228 KB
testcase_12 AC 109 ms
14,468 KB
testcase_13 AC 161 ms
16,728 KB
testcase_14 AC 26 ms
9,728 KB
testcase_15 AC 5 ms
7,808 KB
testcase_16 AC 5 ms
7,808 KB
testcase_17 AC 5 ms
8,064 KB
testcase_18 AC 75 ms
12,192 KB
testcase_19 AC 52 ms
11,012 KB
testcase_20 AC 118 ms
14,924 KB
testcase_21 AC 184 ms
17,428 KB
testcase_22 AC 71 ms
12,236 KB
testcase_23 AC 107 ms
14,428 KB
testcase_24 AC 103 ms
14,376 KB
testcase_25 AC 36 ms
11,452 KB
testcase_26 AC 147 ms
21,844 KB
testcase_27 AC 71 ms
15,232 KB
testcase_28 AC 9 ms
9,600 KB
testcase_29 AC 14 ms
9,984 KB
testcase_30 AC 43 ms
12,928 KB
testcase_31 AC 58 ms
11,596 KB
testcase_32 AC 105 ms
17,684 KB
testcase_33 AC 155 ms
17,056 KB
testcase_34 AC 4 ms
7,936 KB
testcase_35 AC 4 ms
7,936 KB
testcase_36 AC 60 ms
11,268 KB
testcase_37 AC 58 ms
11,904 KB
testcase_38 AC 120 ms
14,848 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/* -*- coding: utf-8 -*-
 *
 * 2805.cc:  No.2805 Go to School - yukicoder
 */

#include<cstdio>
#include<vector>
#include<queue>
#include<algorithm>
#include<utility>

using namespace std;

/* constant */

const int MAX_N = 200000;
const long long LINF = 1LL << 62;

/* typedef */

using ll = long long;
using pii = pair<int,int>;
using pli = pair<ll,int>;
using vpii = vector<pii>;

/* global variables */

vpii nbrs[MAX_N];
int ts[MAX_N];
ll ds0[MAX_N], ds1[MAX_N];

/* subroutines */

void dijkstra(int n, int st, ll ds[]) {
  fill(ds, ds + n, LINF);
  ds[st] = 0;

  priority_queue<pli> q;
  q.push({0, st});

  while (! q.empty()) {
    auto [ud, u] = q.top(); q.pop();
    ud = -ud;
    if (ds[u] != ud) continue;

    for (auto [v, t]: nbrs[u]) {
      ll vd = ud + t;
      if (ds[v] > vd) {
	ds[v] = vd;
	q.push({-vd, v});
      }
    }
  }
}

/* main */

int main() {
  int n, m, l, s, e;
  scanf("%d%d%d%d%d", &n, &m, &l, &s, &e);

  for (int i = 0; i < m; i++) {
    int u, v, t;
    scanf("%d%d%d", &u, &v, &t);
    u--, v--;
    nbrs[u].push_back({v, t});
    nbrs[v].push_back({u, t});
  }

  for (int i = 0; i < l; i++) scanf("%d", ts + i), ts[i]--;

  dijkstra(n, 0, ds0);
  dijkstra(n, n - 1, ds1);

  ll mind = LINF;
  for (int i = 0; i < l; i++)
    if (ds0[ts[i]] < s + e) {
      ll d = max(ds0[ts[i]] , (ll)s) + 1 + ds1[ts[i]];
      mind = min(mind, d);
    }

  printf("%lld\n", (mind < LINF) ? mind : -1LL);
  
  return 0;
}
0