#include #include #include #include #include #include #include #include #include #include #include #include #include #include #define debug_value(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << #x << "=" << x << endl; #define debug(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << x << endl; template inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } using namespace std; typedef long long ll; template vector> vec2d(int n, int m, T v){ return vector>(n, vector(m, v)); } template vector>> vec3d(int n, int m, int k, T v){ return vector>>(n, vector>(m, vector(k, v))); } template void print_vector(vector v, char delimiter=' '){ if(v.empty()) { cout << endl; return; } for(int i = 0; i+1 < v.size(); i++) cout << v[i] << delimiter; cout << v.back() << endl; } int main(){ ios::sync_with_stdio(false); cin.tie(0); cout << setprecision(10) << fixed; int h, w; cin >> h >> w; vector s(h); for(int i = 0; i < h; i++) cin >> s[i]; auto to_idx = [&](int i, int j){ return i*w+j+1; }; atcoder::mf_graph mf(h*w+2); int f = 0, t = h*w+1; int cnt = 0; for(int i = 0; i < h; i++){ for(int j = 0; j < w; j++){ if(s[i][j] == 'h') mf.add_edge(to_idx(i, j), t, 1); if(s[i][j] == 'r') { mf.add_edge(f, to_idx(i, j), 1); cnt++; } } } for(int i = 0; i < h; i++){ vector v; for(int j = 0; j < w; j++){ if(s[i][j] == 'h') v.push_back(j); } for(int j = 0; j < w; j++){ if(s[i][j] == 'r'){ auto p = lower_bound(v.begin(), v.end(), j); if(p != v.end()){ int jj = *p; mf.add_edge(to_idx(i, j), to_idx(i, jj), 1); } if(p != v.begin()){ int jj = *prev(p); mf.add_edge(to_idx(i, j), to_idx(i, jj), 1); } } } } for(int j = 0; j < w; j++){ vector v; for(int i = 0; i < h; i++){ if(s[i][j] == 'h') v.push_back(i); } for(int i = 0; i < h; i++){ if(s[i][j] == 'r') { auto p = lower_bound(v.begin(), v.end(), i); if(p != v.end()){ int ii = *p; mf.add_edge(to_idx(i, j), to_idx(ii, j), 1); } if(p != v.begin()){ int ii = *prev(p); mf.add_edge(to_idx(i, j), to_idx(ii, j), 1); } } } } int flow = mf.flow(f, t); if(flow == cnt){ cout << "Yes" << endl; }else{ cout << "No" << endl; } }