#include #include using namespace std; struct UF{ vector par,sz; vector> mergeTree; UF(int n, bool useMergeTree = false){ sz.resize(n); par.resize(n); for(int i=0;isz[y]) swap(x,y); sz[y] += sz[x]; par[x] = y; } bool same(int x,int y){return find(x)==find(y);} void merge(int child,int parent){ //parentが親,merge過程を表す木などで使用 child = find(child); parent = find(parent); if(child==parent) return; mergeTree[parent].push_back(child); sz[parent] += sz[child]; par[child] = parent; } }; #include #include using namespace atcoder; using mint = modint998244353; string s[510]; int dx[4] = {1,0,-1,0}; int dy[4] = {0,1,0,-1}; string dir = "RULD"; int main(){ int i,j,k,h,w; cin >> h >> w; for(i=0;i> s[i]; UF uf1(h*w), uf2(4*h*w); auto isIn = [&](int x,int y){ if(0<=x && x