#include #include #include #define MOD 998244353 using namespace std; class UnionFind { protected: vector root_of, size_of; size_t group; virtual size_t retrieve_true_root_of(const size_t index) { return root_of[index] == index ? index : root_of[index] = retrieve_true_root_of(root_of[index]); } public: UnionFind(const size_t N) : root_of(vector(N)), size_of(N, 1), group(N) { for (size_t i = 0; i != N; ++i) root_of[i] = i; } virtual bool is_connected(const size_t a, const size_t b) { return retrieve_true_root_of(a) == retrieve_true_root_of(b); } virtual bool merge(const size_t a, const size_t b) { if (retrieve_true_root_of(a) != retrieve_true_root_of(b)) { size_of[root_of[a]] += size_of[root_of[b]]; root_of[b] = root_of[root_of[b]] = root_of[a]; --group; return true; } else return false; } size_t size_of_group_of(const size_t index) { return size_of[retrieve_true_root_of(index)]; } size_t groups() { return group; } }; class MergingUnionFind : public UnionFind { protected: vector value_of; vector data_of; public: MergingUnionFind(const size_t N, const vector& initializer) : UnionFind(N), value_of(N), data_of(initializer) { for (size_t i = 0; i != N; ++i) value_of[i] = initializer[i]; } virtual bool merge(const size_t a, const size_t b) { if (retrieve_true_root_of(a) != retrieve_true_root_of(b)) { size_of[root_of[a]] += size_of[root_of[b]]; value_of[root_of[a]] += value_of[root_of[b]]; root_of[b] = root_of[root_of[b]] = root_of[a]; --group; return true; } else return false; } int get_individual_value_of(const size_t index) { return data_of[index]; } long long get_total_value_of(const size_t index) { return value_of[retrieve_true_root_of(index)]; } int modify(const size_t index, const int value) { value_of[retrieve_true_root_of(index)] -= data_of[index]; data_of[index] = value; value_of[root_of[index]] += data_of[index]; return value; } }; int main() { cin.tie(nullptr); ios::sync_with_stdio(false); uint32_t N, M, i, U, V; cin >> N >> M; int32_t ans = 1; vector A(N); for (i = 0; i != N; ++i) cin >> A[i]; MergingUnionFind muf(N, A); for (i = 0; i != M; ++i) { cin >> U >> V; muf.merge(U - 1, V - 1); } for (i = 0; i != N; ++i) ans = ans * (muf.get_total_value_of(i) % MOD) % MOD; cout << ans << '\n'; return 0; }