#include #include #include #include #include #include #include #include #include #include #include using namespace std; typedef long long ll; struct Node { int v; int X; int Y; Node(int v = -1, int X = -1, int Y = -1) { this->v = v; this->X = X; this->Y = Y; } bool operator>(const Node &n) const { return X < n.X; } }; int main() { int N, M, S, T; cin >> N >> M >> S >> T; int P[N]; for (int i = 0; i < N; ++i) { cin >> P[i]; } vector E[N + 1]; for (int i = 0; i < M; ++i) { int a, b; cin >> a >> b; E[a].push_back(b); E[b].push_back(a); } priority_queue , greater> pque; pque.push(Node(S, P[S - 1], 0)); int visited[N + 1]; memset(visited, -1, sizeof(visited)); int ans = 0; while (not pque.empty()) { Node node = pque.top(); pque.pop(); if (visited[node.v] >= node.Y) continue; visited[node.v] = node.Y; ans = max(ans, node.Y); for (int u : E[node.v]) { int p = P[u - 1]; Node next(u, node.X, node.Y); if (node.X > p) { next.X = p; next.Y += 1; } pque.push(next); } } cout << ans << endl; return 0; }