結果
| 問題 |
No.2805 Go to School
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-07-12 22:12:54 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 233 ms / 2,000 ms |
| コード長 | 1,453 bytes |
| コンパイル時間 | 2,346 ms |
| コンパイル使用メモリ | 205,040 KB |
| 実行使用メモリ | 24,108 KB |
| 最終ジャッジ日時 | 2025-04-09 15:39:21 |
| 合計ジャッジ時間 | 7,116 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 36 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
template<typename T>
bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template<typename T>
bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
void solve();
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
cout << fixed << setprecision(20);
int t = 1;
//cin >> t;
while (t--) {
solve();
}
}
int N,M,L,S,E;
vector<pair<int,int>>g[2<<17];
bool flag[2<<17];
vector<ll>dijk(int sv){
vector<ll>dist(N,(ll)1<<60);
dist[sv]=0;
priority_queue<pair<ll,int>,vector<pair<ll,int>>,greater<>>que;
que.push({0,sv});
while(!que.empty()){
auto[d,v]=que.top();
que.pop();
if(dist[v]<d)continue;
for(auto[vv,dd]:g[v]){
if(chmin(dist[vv],dist[v]+dd)){
que.push({dist[vv],vv});
}
}
}
return dist;
}
void solve() {
cin>>N>>M>>L>>S>>E;
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);
}
rep(i,L){
int T;cin>>T,--T;
flag[T]=1;
}
vector dist0=dijk(0),distN=dijk(N-1);
ll ans=(ll)1<<60;
rep(i,N){
if(!flag[i])continue;
if(dist0[i]==(ll)1<<60)continue;
if(distN[i]==(ll)1<<60)continue;
if(S+E<=dist0[i])continue;
chmin(ans,max(dist0[i],(ll)S)+1+distN[i]);
}
if(ans==(ll)1<<60)ans=-1;
cout<<ans<<endl;
}