#include namespace { #pragma GCC diagnostic ignored "-Wunused-function" #include #pragma GCC diagnostic warning "-Wunused-function" using namespace std; using namespace atcoder; #define rep(i,n) for(int i = 0; i < (int)(n); i++) #define rrep(i,n) for(int i = (int)(n) - 1; i >= 0; i--) #define all(x) begin(x), end(x) #define rall(x) rbegin(x), rend(x) template bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; } template bool chmin(T& a, const T& b) { if (b < a) { a = b; return true; } else return false; } using ll = long long; using P = pair; using VI = vector; using VVI = vector; using VL = vector; using VVL = vector; } int main() { ios::sync_with_stdio(false); cin.tie(0); int h, w; cin >> h >> w; vector s(h); VI v0, v1; rep(i, h) { cin >> s[i]; rep(j, w) { if (s[i][j] == 'r') v0.emplace_back(i * w + j); else if (s[i][j] == 'h') v1.emplace_back(i * w + j); } } const int hw = h * w, b0 = hw + hw, b1 = b0 + v0.size(), src = b1 + v1.size(), snk = src + 1; mf_graph g(snk + 1); rep(i, h - 1) rep(j, w) { int u = i * w + j, v = u + w; if (s[i][j] != 'h') g.add_edge(u, v, 1); if (s[i+1][j] != 'h') g.add_edge(v, u, 1); } rep(i, h) rep(j, w - 1) { int u = hw + i * w + j, v = u + 1; if (s[i][j] != 'h') g.add_edge(u, v, 1); if (s[i][j + 1] != 'h') g.add_edge(v, u, 1); } rep(i, v0.size()) { g.add_edge(src, b0 + i, 1); g.add_edge(b0 + i, v0[i], 1); g.add_edge(b0 + i, v0[i] + hw, 1); } rep(j, v1.size()) { g.add_edge(b1 + j, snk, 1); g.add_edge(v1[j], b1 + j, 1); g.add_edge(v1[j] + hw, b1 + j, 1); } int f = g.flow(src, snk); cout << (f == v0.size() ? "Yes\n" : "No\n"); }