#include #define rep(i, a, n) for(int i = a; i < n; i++) #define all(a) a.begin(), a.end() #define int long long #define chmax(x, y) x = max(x, y) #define chmin(x, y) x = min(x, y) using namespace std; typedef pair P; const int INF = 1e18; int n, m, k, s, t; vector

d[200010]; signed main(){ ios::sync_with_stdio(false); cin.tie(0); cin >> n >> m >> k >> s >> t; rep(i, 0, m){ int a, b, c; cin >> a >> b >> c; assert(1 <= a && a <= n - 1 && 1 <= b && b <= k && 1 <= c && c <= k); a--; d[a].push_back(P(b, c)); } vector

pre; pre.push_back(P(s, 0)); d[n - 1].push_back(P(t, -1)); rep(i, 0, n){ cerr << "now " << i << " ,next " << i + 1 << "====================================" << endl; vector

next; rep(j, 0, pre.size()){ if(next.size()){ P p = next.back(); if(p.second + abs(p.first - pre[j].first) <= pre[j].second){ continue; } } while(next.size()){ P p = next.back(); if(p.second > pre[j].second + abs(p.first - pre[j].first)){ next.pop_back(); }else{ next.push_back(pre[j]); break; } } if(next.size() == 0){ next.push_back(pre[j]); } } cerr << "next : " << endl; rep(j, 0, next.size()){ cerr <