#include #include #include using namespace std ; int off, h, w, r=0 ; vector b ; int f(int i, int j) { return off * (i + 1) + (j + 1) ; } void chase(int at) { if (b[at] == 'C') b[at] = 0 ; if (b[at] == 'W' || b[at] == 0) return ; b[at] = 0 ; for (int i : vector{-1, 1, -off, off}) chase(at+i) ; } map nodeid ; vector > edges ; int addnode(int v) { if (nodeid.find(v) == nodeid.end()) { int sz = nodeid.size() ; nodeid[v] = 1 + sz ; } return nodeid[v] ; } void addedge(int a, int b) { edges.push_back(make_pair(a, b)) ; } void cleargraph() { nodeid.clear() ; edges.clear() ; } const int MAXN = 50 * 50 + 2 ; int cap[MAXN][MAXN] ; int flow[MAXN][MAXN] ; char seen[MAXN] ; int q[MAXN], pred[MAXN] ; int augment(int at, int n) { q[0] = at ; int qg = 0 ; int qp = 1 ; for (int i=0; ifirst & 1) cap[0][it->second] = 1 ; else cap[it->second][n-1] = 1 ; } for (auto p : edges) cap[p.first][p.second] = 1 ; int r = 0 ; while (augment(0, n)) r++ ; return r ; } void chase2(int at) { if (b[at] != 'C') return ; int src = addnode(at) ; b[at] = 'c' ; for (int i : vector{-1, 1, -off, off}) { if (b[at+i] == 'C' || b[at+i] == 'c') { if (at & 1) addedge(src, addnode(at+i)) ; chase2(at+i) ; } } } int main() { cin >> h >> w ; b = vector((h+3)*(w+3)) ; off = w + 1 ; if ((off & 1) == 0) off++ ; for (int i=0; i> b[f(i,j)] ; for (int i=0; i