#include #define NMAX 1007 using namespace std; int n, m, a[NMAX], Ap[NMAX], d, H[NMAX], T[NMAX], Ans; int father(int f){ if(T[f] == f) return f; return father(T[f]); } void unite(int x, int y){ if(H[x] > H[y]) T[y] = x; else if(H[x] < H[y]) T[x] = y; else{ ++ H[x]; T[y] = x; } } int main(){ cin >> d >> n >> m; for(int i = 1; i <= n; ++i) cin >> a[i]; for(int i = 1; i <= d; ++i) T[i] = i; for(int i = 1; i <= m; ++i){ int A, B; cin >> A >> B; int Ta = father(A); int Tb = father(B); if(Ta != Tb) unite(Ta, Tb); } for(int i = 1; i <= n; ++i) Ap[father(a[i])]++; for(int i = 1; i <= d; ++i) if(Ap[i] != 0) ++Ans; cout << Ans; return 0; }