結果
問題 | No.2805 Go to School |
ユーザー |
|
提出日時 | 2024-07-12 22:00:43 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 279 ms / 2,000 ms |
コード長 | 1,676 bytes |
コンパイル時間 | 2,310 ms |
コンパイル使用メモリ | 206,940 KB |
最終ジャッジ日時 | 2025-02-22 04:02:19 |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 35 |
ソースコード
#include<bits/stdc++.h>using namespace std;using ll=long long;#define all(v) v.begin(),v.end()#define rall(v) v.rbegin(),v.rend()template<class T> bool chmax(T &a, T b){if (a < b){a = b;return true;} else return false;}template<class T> bool chmin(T &a, T b){if (a > b){a = b;return true;} else return false;}const ll INF=1LL<<60;int main(){ios::sync_with_stdio(false);cin.tie(nullptr);int N,M,L;ll S,E;cin>>N>>M>>L>>S>>E;vector<vector<pair<int,ll>>>G(N);for(int i=0;i<M;i++){int a,b;ll t;cin>>a>>b>>t;a--;b--;G[a].push_back(make_pair(b,t));G[b].push_back(make_pair(a,t));}vector<int>T(L);for(int i=0;i<L;i++){cin>>T[i];T[i]--;}auto f=[&](int s)-> vector<ll> {priority_queue<pair<ll,int>,vector<pair<ll,int>>,greater<pair<ll,int>>>pq;pq.push(make_pair(0,s));vector<ll>dist(N,INF);dist[s]=0;while(pq.size()){auto[c,x]=pq.top();pq.pop();if(dist[x]<c)continue;for(auto[i,e]:G[x]){if(chmin(dist[i],c+e)){pq.push(make_pair(dist[i],i));}}}return dist;};vector<ll>ds=f(0),dt=f(N-1);if(ds[N-1]==INF){cout<<-1<<"\n";}else{ll ans=INF;for(int i=0;i<L;i++){int t=T[i];if(ds[t]==INF||dt[t]==INF)continue;if(ds[t]<=S+E-1){chmin(ans,max(S,ds[t])+1+dt[t]);}}if(ans==INF)cout<<-1<<"\n";else cout<<ans<<"\n";}}