結果
| 問題 |
No.2805 Go to School
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-08-14 22:54:41 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 395 ms / 2,000 ms |
| コード長 | 1,634 bytes |
| コンパイル時間 | 1,086 ms |
| コンパイル使用メモリ | 126,140 KB |
| 実行使用メモリ | 34,876 KB |
| 最終ジャッジ日時 | 2025-04-09 15:43:01 |
| 合計ジャッジ時間 | 9,166 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 36 |
ソースコード
#include<iostream>
#include<string>
#include<queue>
#include<vector>
#include<cassert>
#include<random>
#include<set>
#include<map>
#include<cassert>
#include<unordered_map>
#include<bitset>
#include<numeric>
#include<algorithm>
using namespace std;
typedef long long ll;
const int inf=1<<30;
const ll INF=1LL<<62;
typedef pair<int,ll> P;
typedef pair<int,P> PP;
const ll MOD=998244353;
int main(){
int N,M,L,S,E;
cin>>N>>M>>L>>S>>E;
vector<vector<P>> G(2*N);
for(int i=0;i<M;i++){
int a,b,t;
cin>>a>>b>>t;
a--;b--;
G[a].push_back(P(b,t));
G[b].push_back(P(a,t));
G[a+N].push_back(P(b+N,t));
G[b+N].push_back(P(a+N,t));
}
vector<bool> T(2*N);
for(int i=0;i<L;i++){
int a;
cin>>a;
a--;
T[a]=true;
}
vector<ll> dist(2*N,INF);
priority_queue<pair<ll,int>,vector<pair<ll,int>>,greater<pair<ll,int>>> pq;
pq.push({0,0});
if(T[0]){
pq.push({S+1,0+N});
}
while(!pq.empty()){
auto [d,v]=pq.top();pq.pop();
if(dist[v]<=d) continue;
//dist[v]>d
dist[v]=d;
for(auto [to,c]:G[v]){
if(T[to] && d+c<=S){
//頂点toに止まることができる
pq.push({S+1,N+to});
}
if(d+c<dist[to]){
pq.push({d+c,to});
}
if(S<=d+c && d+c<S+E && T[to]){
//頂点toに止まって用をたす
pq.push({d+c+1,to+N});
}
}
}
//N+N-1
ll ans=dist[2*N-1];
cout<<(ans==INF?-1:ans)<<endl;
}