結果
問題 | No.2805 Go to School |
ユーザー |
|
提出日時 | 2024-07-12 22:48:32 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 298 ms / 2,000 ms |
コード長 | 1,519 bytes |
コンパイル時間 | 4,566 ms |
コンパイル使用メモリ | 259,336 KB |
最終ジャッジ日時 | 2025-02-22 04:53:59 |
ジャッジサーバーID (参考情報) |
judge3 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 35 |
ソースコード
#include <bits/stdc++.h>#include <atcoder/all>using namespace std;using ll = long long;#define rep(i, s, t) for (ll i = s; i < (ll)(t); i++)template<typename T>bool chmin(T &x, T y) { return x > y ? (x = y, true) : false; }template<typename T>bool chmax(T &x, T y) { return x < y ? (x = y, true) : false; }struct io_setup {io_setup() {ios::sync_with_stdio(false);std::cin.tie(nullptr);cout << fixed << setprecision(15);}} io_setup;using mint = atcoder::modint1000000007;int main(){int n,m,l,s,e;cin>>n>>m>>l>>s>>e;vector<vector<pair<ll,ll>>> g(n);rep(i,0,m){int a,b,t;cin>>a>>b>>t;a--; b--;g.at(a).push_back({b,t});g.at(b).push_back({a,t});}vector<int> t(l);rep(i,0,l) cin>>t.at(i),t.at(i)--;vector<ll> dist1(n,1e18),dist2(n,1e18);priority_queue<pair<ll,ll>,vector<pair<ll,ll>>,greater<pair<ll,ll>>> pq;{pq.push({0,0});while(!pq.empty()){auto[cs,nw]=pq.top();pq.pop();if(dist1.at(nw)!=1e18) continue;dist1.at(nw)=cs;for(auto[nx,ad]:g.at(nw)){if(dist1.at(nx)!=1e18) continue;pq.push({cs+ad,nx});}}}{pq.push({0,n-1});while(!pq.empty()){auto[cs,nw]=pq.top();pq.pop();if(dist2.at(nw)!=1e18) continue;dist2.at(nw)=cs;for(auto[nx,ad]:g.at(nw)){if(dist2.at(nx)!=1e18) continue;pq.push({cs+ad,nx});}}}ll ans=1e18;rep(i,0,l){int d=t.at(i);if(dist1.at(d)<s+e){chmin(ans,max(dist1.at(d),(ll)s)+1+dist2.at(d));}}if(ans==1e18) ans=-1;cout<<ans<<endl;}