#include using namespace std; using ll = long long; using P = pair; #define fix(x) fixed << setprecision(x) #define asc(x) x, vector, greater #define rep(i, n) for(ll i = 0; i < n; i++) #define all(x) (x).begin(),(x).end() templatebool chmin(T&a, const T&b){if(a>b){a=b;return 1;}return 0;} templatebool chmax(T&a, const T&b){if(a par, siz; UnionFind(int N) : par(N), siz(N,1){ rep(i,N) par[i] = i; } int root(int x){ if(par[x]==x) return x; return par[x] = root(par[x]); } bool unite(int x,int y){ x = root(x); y = root(y); if(x==y) return false; if(siz[x]> n >> m; UnionFind uf(n); vector a(n); rep(i,n) cin >> a[i]; rep(i,m){ int u,v; cin >> u >> v; uf.unite(u-1,v-1); } vector ans(n,0); rep(i,n) ans[uf.root(i)] = (ans[uf.root(i)] + a[i]) % MOD; ll tot = 1; rep(i,n) tot = tot * ans[uf.root(i)] % MOD; cout << tot << '\n'; return 0; }