#include using namespace std; constexpr uint64_t infinity=-(1llu<<50llu); typedef pair E; vector> e,r; 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); } auto sshpath=[n](vector> const &g,int s){ priority_queue,greater> djk; vector d(n,infinity); djk.emplace(d[s]=0,s); while (not djk.empty()){ int x=djk.top().second,c=djk.top().first; djk.pop(); if (c==d[x]) for (auto y: g[x]) if (d[x]+y.first>=1ll){ uint64_t mid=(lef+rad); // Make a reduced graph with only legal vertices and edges. // An edge is legal if its length + end potential <= mid. decltype(e) e2(n); vector r2(n,0); for (int i=0; i bfs; vector path(n,0); for (int i=0; i=etime); // Check for cycles. bool cycle=false; for (int i=n; i--;) if (r2[i]) cycle=true, possible=true; // cerr<<"possible "<