結果
問題 | No.2805 Go to School |
ユーザー |
![]() |
提出日時 | 2024-07-13 16:15:08 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 383 ms / 2,000 ms |
コード長 | 1,796 bytes |
コンパイル時間 | 4,194 ms |
コンパイル使用メモリ | 257,572 KB |
最終ジャッジ日時 | 2025-02-22 06:25:34 |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 35 |
ソースコード
#include <bits/stdc++.h>#include <atcoder/all>using namespace std;using namespace atcoder;#define rep(i, n) for(int i=0;i<(n);++i)#define rep1(i, n) for(int i=1;i<=(n);i++)#define ll long longusing mint = modint998244353;using P = pair<ll,ll>;using lb = long double;using T = tuple<ll, ll, ll>;#ifdef LOCAL# include <debug_print.hpp># define dbg(...) debug_print::multi_print(#__VA_ARGS__, __VA_ARGS__)#else# define dbg(...) (static_cast<void>(0))#endifint main(){int n, m, l, s, e;cin >> n >> m >> l >> s >> e;vector<vector<P>> g(n);rep(i,m) {int a, b, t;cin >> a >> b >> t;--a;--b;g[a].emplace_back(b, t);g[b].emplace_back(a, t);}vector<int> t(l);rep(i,l) cin >> t[i];rep(i,l) --t[i];const ll INF = 1e18;vector<ll> dist(n, INF), rdist(n, INF);dist[0] = 0;rdist[n-1] = 0;priority_queue<P, vector<P>, greater<P>> pq;pq.emplace(0, 0);while(!pq.empty()) {auto [d, u] = pq.top();pq.pop();if(dist[u]!=d) continue;for(auto [v, c] : g[u]) {if(dist[v]>dist[u] + c) {dist[v] = dist[u] + c;pq.emplace(dist[v], v);}}}pq.emplace(0, n-1);while(!pq.empty()) {auto [d, u] = pq.top();pq.pop();if(rdist[u]!=d) continue;for(auto [v, c] : g[u]) {if(rdist[v]>rdist[u] + c) {rdist[v] = rdist[u] + c;pq.emplace(rdist[v], v);}}}ll ans = INF;dbg(dist, rdist);rep(i,l) {if(dist[t[i]]<=s+e) {ans = min(ans, max((ll)s, dist[t[i]])+1+rdist[t[i]]);}}if(ans==INF) ans = -1;cout << ans << endl;return 0;}