#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #pragma warning(disable:4996) //#define ATCODER #ifdef ATCODER #include #endif typedef long long ll; typedef unsigned long long ull; #define LINF 9223300000000000000 #define LINF2 1223300000000000000 #define LINF3 1000000000000 #define INF 2140000000 const long long MOD = 1000000007; //const long long MOD = 998244353; using namespace std; #ifdef ATCODER using namespace atcoder; #endif class UF { private: int num; vector par; vector siz; public: //vector val; public: UF(int n) : num(n) { par.resize(n); siz.resize(n); //val.resize(n); int i; for (i = 0; i < n; i++) { par[i] = i; siz[i] = 1; //val[i]=0; } } int find(int x) { if (x == par[x]) return x; return par[x] = find(par[x]); } void unite(int x, int y) { x = find(x); y = find(y); if (x == y) return; if (siz[x] < siz[y]) { par[x] = y; siz[y] = siz[x] + siz[y]; //val[y]=val[x]+val[y]; } else { par[y] = x; siz[x] = siz[x] + siz[y]; //val[x]=val[x]+val[y]; } } bool same(int x, int y) { return find(x) == find(y); } int size(int x) { return siz[find(x)]; } int ngroup() { //int ngroup( int& ans ) { int count = 0; int i; for (i = 0; i < num; i++) { if (par[i] == i) { count++; //ans += (val[i]? siz[i]: siz[i]-1); } } return count; } }; void solve() { int n, m, s, t; scanf("%d%d%d%d", &n, &m, &s, &t); s--; t--; vector p(n),a(m),b(m); int i,k; for (i = 0; i < n; i++) { scanf("%d", &p[i]); } map> z; for (i = 0; i < m; i++) { scanf("%d%d", &a[i], &b[i]); a[i]--; b[i]--; int tmp = min(p[a[i]], p[b[i]]); z[tmp].push_back(i); } UF uf(n); int ans = 0; int pre = 1; auto it = z.rbegin(); for (; it != z.rend(); it++) { int tmp = it->first; vector& v = it->second; for (k = 0; k < (int)v.size(); k++) { int id = v[k]; uf.unite(a[id], b[id]); } int nn=uf.size(s); //printf("%d\n", nn); if (pre < nn && tmp < p[s]) { ans++; } pre = nn; //if (uf.same(s, t)) break; } printf("%d\n", ans); return; } int main() { #if 1 solve(); #else int T, t; scanf("%d", &T); for (t = 0; t < T; t++) { //cout << "Case #" << t + 1 << ": "; solve(); } #endif return 0; }