#include #include #include #include #include using namespace std; using i64 = long long; constexpr i64 inf = 987654321987654321LL; struct edge { int to, cost; }; int N, M, K, S, T; vector> ABC; // x棟が開始する番号を返す int myfind(int x) { if(x >= N-1) { return M; } int lo = -1, hi = M-1; while(hi - lo > 1) { int md = (lo + hi) / 2; int cand = get<0>(ABC[md]); if(x <= cand) { hi = md; } else { lo = md; } } return hi; } int main(void) { scanf("%d%d%d%d%d", &N, &M, &K, &S, &T); --S, --T; // G[i] := { (i棟の始点の階, i+1棟の終点の階)のリスト } vector>> G(N); // vector> corr0(M), corr1(M); // corr0[i] := 渡り廊下始点の (棟, 階) // // corr1[i] := 渡り廊下終点の (棟, 階) vector> corr0_rev(N); for(int i=0; i> H(M+2); for(int a=0; a 1棟 q階への渡り廊下 // int node1 = corr0_rev[0][p]; // H[M].push_back(edge{node1, abs(S - p)}); // } // for(auto pr0 : G[N-2]) { // int b, c; tie(b, c) = pr0; // N-2棟 b階 -> N-1棟 c階への渡り廊下 // int node0 = corr0_rev[N-2][b]; // H[node0].push_back(edge{M+1, abs(c - T)}); // } // // // コーナーケース // if(N == 1) { // H[M].push_back(edge{M+1, abs(S - T)}); // } // // vector cost(M+2, inf); // cost[M+2] // cost[M] = 0; // priority_queue, vector>, greater>> pq; // vector seen(M+2, false); // seen[M+2] // // コスト、点番号 // pq.emplace(0, M); // while(!pq.empty()) { // i64 _, v; tie(_, v) = pq.top(); pq.pop(); // if(seen[v]) { continue; } // seen[v] = true; // for(edge e : H[v]) { // if(cost[e.to] > cost[v] + e.cost) { // cost[e.to] = cost[v] + e.cost; // pq.emplace(cost[e.to], e.to); // } // } // } // i64 res = cost[M+1]; // if(res == inf) { res = -1; } // printf("%lld\n", res); return 0; }