#include #include using namespace std; using namespace atcoder; using ll = long long; using mint = modint998244353; struct UnionFind { int ngroup, N; vector par, siz; UnionFind(int _N) : N(_N), par(_N), siz(_N){ ngroup = _N; for(int i = 0; i < N; i++) par[i] = i, siz[i] = 1; } int root(int x) { if (par[x] == x) return x; return par[x] = root(par[x]); } int unite(int x, int y) { int rx = root(x), ry = root(y); if (rx == ry) return rx; ngroup--; if (siz[rx] > siz[ry]) swap(rx, ry); par[rx] = ry; siz[ry] += siz[rx]; return ry; } bool same(int x, int y) { int rx = root(x), ry = root(y); return rx == ry; } int size(int x) {return siz[root(x)];} int group_count() {return ngroup;} vector> groups(){ vector rev(N); int nrt=0; for (int i=0; i> res(nrt); for (int i=0; i> N >> M; vector A(N); vector P(N); mint ans=1; for (int i=0; i> A[i]; UnionFind tree(N); for (int i=0; i> U >> V; U--; V--; tree.unite(U, V); } for (int i=0; i