#include #include #include #include using namespace std; using i64 = long long; int a, b, c; map cost[200005]; vector>> G; i64 cc; int p, q; i64 _cost; int src, dst; int k; i64 v; int main(void) { constexpr i64 inf = 987654321987654321LL; int N, M, K, S, T; scanf("%d%d%d%d%d", &N, &M, &K, &S, &T); --S, --T; priority_queue, vector>, greater>> pq; pq.emplace(0, 0, S); cost[0][S] = 0; G.resize(N); for(int i=0; i _cost + abs(q - src)) { cost[p+1][dst] = _cost + abs(q - src); pq.emplace(cost[p+1][dst], p+1, dst); } } } i64 mini = inf; for(auto&& kv : cost[N-1]) { mini = min(mini, kv.second + abs(T - kv.first)); } if(mini == inf) { mini = -1; } printf("%lld\n", mini); return 0; }