#include #include #include using namespace std; using namespace __gnu_pbds; template using ordered_set = tree, rb_tree_tag, tree_order_statistics_node_update>; #define ld long double #define nl cout << "\n"; #define getunique(v) {sort(v.begin(), v.end()); v.erase(unique(v.begin(), v.end()), v.end());} #define forn(a, b) for (int i = a; i < b; i++) #define __builtin_popcountll __builtin_popcountll #define __builtin_clzll __builtin_clzll #define __builtin_ctzll __builtin_ctzll #define yesno(b) cout << ((b)? "YES" : "NO"); #define pii pair #define mp(a, b) make_pair(a, b) #define pb push_back #define all(a) a.begin(), a.end() #define vi vector #define hhh cout << "here" << endl; #define mod1 1000000007 #define mod2 998244353ll void solve() { int n, m; cin >> n >> m; long long ans = 1ll; vector adj[n + 1]; vector v(n + 1); for(int i = 1 ; i <= n ; i++) cin >> v[i]; for(int i = 0 ; i < m ; i++) { int u, v; cin >> u >> v; adj[u].push_back(v); adj[v].push_back(u); } vector vis(n + 1, 0); for(int i = 1 ; i <= n ; i++) { if(vis[i]) continue; queue q; long long sum = 0, cnt = 0; q.push(i); vis[i] = 1; sum += v[i], cnt = 1; while(!q.empty()) { int x = q.front(); q.pop(); for(int y : adj[x]) { if(vis[y]) continue; vis[y] = 1; q.push(y); sum += v[y]; cnt++; } } // cout << sum << " " << cnt << endl; long long prod = 1ll; while(cnt) { prod = (prod * sum) % mod2; cnt--; } ans = (ans * prod) % mod2; } cout << ans; } signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); // freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); int t = 1; // cin >> t; while (t--) { solve(); nl; } return 0; }