#include using namespace std; constexpr int64_t infinity=(1llu<<60llu); typedef pair E; vector> e,r; int main(){ int64_t stime,etime; cin>>stime>>etime; int n,m; cin>>n>>m; e.resize(n); r.resize(n); while (m--){ int a,b; int64_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; int64_t c=djk.top().first; djk.pop(); if (c==d[x]) for (auto y: g[x]) if (d[x]+y.first>=1ll){ int64_t mid=(lef+rad); // Make a reduced graph with only legal vertices and edges. vector reachable(n); stack dfs; for (int i=0; i r2(n,0); for (int i=0; i bfs; vector path(n,-infinity); for (int i=0; i=etime); // Check for reachable cycles. bool cycle=false; for (int i=n; i--;) if (path[i]>=0 and r2[i]) cycle=true, possible=true; if (not possible) lef=mid; } int64_t res=min(lef+1,potential[0]); cout<