結果
| 問題 |
No.2805 Go to School
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-07-12 21:20:48 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 168 ms / 2,000 ms |
| コード長 | 948 bytes |
| コンパイル時間 | 1,038 ms |
| コンパイル使用メモリ | 77,184 KB |
| 実行使用メモリ | 23,712 KB |
| 最終ジャッジ日時 | 2025-04-09 15:36:26 |
| 合計ジャッジ時間 | 4,742 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 36 |
ソースコード
#include<iostream>
#include<queue>
#include<vector>
#include<cassert>
using namespace std;
int N,M,L,S,E;
vector<pair<int,int> >G[2<<17];
vector<long>f(int s)
{
vector<long>ret(N,(long)1e18);
ret[s]=0;
priority_queue<pair<long,int> >Q;
Q.push(make_pair(0,s));
while(!Q.empty())
{
int u=Q.top().second;
long d=-Q.top().first;
Q.pop();
if(ret[u]<d)continue;
for(auto e:G[u])
{
int v=e.first;
long nd=d+e.second;
if(ret[v]>nd)
{
ret[v]=nd;
Q.push(make_pair(-nd,v));
}
}
}
return ret;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
cin>>N>>M>>L>>S>>E;
for(int i=0;i<M;i++)
{
int a,b,c;cin>>a>>b>>c;
a--,b--;
G[a].push_back(make_pair(b,c));
G[b].push_back(make_pair(a,c));
}
vector<long>s=f(0),T=f(N-1);
long ans=1e18;
for(int i=0;i<L;i++)
{
int t;cin>>t;t--;
long v=max(s[t],(long)S);
if(v<S+E)ans=min(ans,v+1+T[t]);
}
if(ans>=(long)1e18)ans=-1;
cout<<ans<<endl;
}