#include #define rep(i, n) for (int i = 0; i < (int) n; i++) using ll = long long; using namespace std; using T = tuple; using P = pair; const long long INF = 1ll << 60; template bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } template bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } int main() { ll n, m, s, t; cin >> n >> m >> s >> t; s--; t--; vector p(n); rep(i, n) cin >> p[i]; vector> vertex(n); rep(i, m) { ll a, b; cin >> a >> b; a--; b--; vertex[a].push_back(b); vertex[b].push_back(a); } priority_queue pri; pri.emplace(p[s], s, 0); vector dp(n); set

seen; seen.insert({s, p[s]}); while (!pri.empty()) { auto[people, now, score] = pri.top(); // cout << people << " " << now << " " << score << endl; pri.pop(); for (auto next:vertex[now]) { if (p[next] < people) { chmax(dp[next], score + 1); pri.emplace(p[next], next, score + 1); seen.insert({next, p[next]}); } else if (seen.end() == seen.find({next, people})) { chmax(dp[next], score); pri.emplace(people, next, score); seen.insert({next, people}); } } } cout << dp[t] << endl; }