結果

問題 No.2805 Go to School
ユーザー HIcoder
提出日時 2024-08-14 22:54:41
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 553 ms / 2,000 ms
コード長 1,634 bytes
コンパイル時間 1,394 ms
コンパイル使用メモリ 127,372 KB
最終ジャッジ日時 2025-02-23 22:44:57
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 35
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

#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;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0