#include #include #include #include #include #include #include #include #include #include using namespace std; typedef long long ll; const ll INF=1LL<<61; typedef pair P; typedef pair PP; const ll MOD=998244353; class UnionFind{ public: std::vector par; std::vector rank; std::vector sz;//sz[i]で,頂点iが含まれているグループのサイズ std::vector root; UnionFind(int size){ rank=std::vector(size+1,0); par = std::vector(size+1,0); std::iota(par.begin(),par.end(),0);//#include sz = std::vector(size+1,1); root=std::vector(size+1); std::iota(root.begin(),root.end(),0); } ~UnionFind(){ std::vector().swap(rank); std::vector().swap(par); std::vector().swap(sz); std::vector().swap(root); } int find(int x){ if(par[x]==x)return x; else return par[x] = find(par[x]); } bool issame(int u,int v){ return find(u)==find(v); } void merge(int u,int v){ u = find(u); v = find(v); if(u==v) return; if(rank[u]=rank[v] par[v]=u; sz[u]+=sz[v]; if(rank[u]==rank[v])rank[u]++; } int size(int u){//頂点uが属すグループの大きさを表す. u=find(u); return sz[u]; } std::map> element(){ std::map> mp; for(int i=0;i0){ if(y&1){ res*=x; res%=mod; } x*=x; x%=mod; y/=2; } return res; } int main(){ int W,H; cin>>W>>H; UnionFind uf(W+10); string S; for(int q=0;q>S; map mpidx; for(int j=0;j check; ll ans=1; for(int j=W;j st; for(int j=0;j