#include using namespace std; vector>> e,r; typedef pair E; int main(){ uint64_t stime,etime; cin>>stime>>etime; int n,m; cin>>n>>m; e.resize(n); r.resize(n); while (m--){ int a,b; uint64_t c; cin>>a>>b>>c; --a,--b; e[a].emplace_back(c,b); r[b].emplace_back(c,a); } priority_queue,greater> djk; vector potential(n,-(1<<29)); djk.emplace(potential[n-1]=0,n-1); while (not djk.empty()){ int x=djk.top().second,c=djk.top().first; djk.pop(); if (c!=potential[x]) continue; for (auto y: r[x]){ if (potential[x]+y.first,uint64_t> best; // best[{time,node}] = (smallest risk) for (uint64_t t=0; t<=etime; t++){ best[{t,0}]=(t>=stime? (t-stime)+potential[0]: 0llu); } while (!best.empty()) { auto best_it = best.begin(); auto t=best_it->first.first; auto x=best_it->first.second; auto risk=best_it->second; best.erase(best.begin()); // cerr<<" risk t="<=etime){ if (risk "<second); best[{t+i.first,i.second}]=min(prev_risk,nrisk); } } res=min(res,potential[0]); cout<