#include #include using namespace std; using namespace atcoder; struct Fast { Fast() { std::cin.tie(nullptr); ios::sync_with_stdio(false); cout << setprecision(10); } } fast; #define rep(i, a, b) for (int(i) = (a); (i) < (int)(b); (i)++) using mint = modint998244353; int main() { int n, m; cin >> n >> m; vector a(n); rep(i, 0, n) cin >> a[i]; vector> g(n, vector()); rep(i, 0, m) { int u, v; cin >> u >> v; u--; v--; g[u].push_back(v); g[v].push_back(u); } vector seen(n, false); vector root(n, -1), size(n, 0); vector sum(n, 0); stack st; rep(i, 0, n) st.push(i); while (!st.empty()) { int x = st.top(); st.pop(); if (seen[x]) continue; seen[x] = true; if (root[x] == -1) root[x] = x; sum[root[x]] += a[x]; size[root[x]]++; for (auto y : g[x]) { if (root[y] != -1) continue; root[y] = root[x]; st.push(y); } } mint ans = 1; rep(i, 0, n) { if (root[i] != i) continue; rep(j, 0, size[i]) ans *= sum[i]; } cout << ans.val() << endl; }