#include #include using mint = atcoder::modint998244353; using namespace std; int main() { int N, M; cin >> N >> M; vector A(N); for (int i = 0; i < N; i++){ cin >> A[i]; } atcoder::dsu uf(N); for (int i = 0; i < M; i++){ int U, V; cin >> U >> V; U--; V--; uf.merge(U, V); } vector X(N); for (auto s : uf.groups()){ mint sum = 0; for (int i : s){ sum += A[i]; } for (int i : s){ X[i] = sum; } } mint ans = 1; for (mint m : X){ ans *= m; } cout << ans.val() << endl; }