#pragma GCC target("avx2") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; // /* #include using namespace atcoder; using mint =modint998244353; //using mint =modint1000000009; //using mint =modint1000000007; #define ip(x) is_prime_constexpr(x) istream &operator>>(istream &is, mint &a) { int v; cin >> v; a = v; return is; } ostream &operator<<(ostream &os, const mint &a) { return os << a.val(); } // */ template istream &operator>>(istream &is, vector &v) { for (auto &e : v) is >> e; return is; } template ostream &operator<<(ostream &os, const vector &v) { for (auto &e : v) os << e << ' '; return os; } typedef long long ll; typedef unsigned long long ull; typedef long double LD; typedef double D; typedef pair P; typedef map M; void tatananonano() { ios::sync_with_stdio(false); std::cin.tie(nullptr); cout<< fixed << setprecision(10); } #define LL(...) ll __VA_ARGS__; IN(__VA_ARGS__) #define STR(...) string __VA_ARGS__; IN(__VA_ARGS__) #define CHR(...) char __VA_ARGS__;IN(__VA_ARGS__) template void scan(T &a) { cin >> a; } void IN() {} template void IN(Head &head, Tail &...tail) {scan(head);IN(tail...);} #define rep(i,n) for(ll i=0;i= (m); --i) #define drep(i, n) drep2(i,0,n) #define fore(i,a) for(const auto &i:a) #define all(x) (x).begin(),(x).end() #define pb push_back #define lb lower_bound #define ub upper_bound #define uni(x) sort(all(x));x.erase(unique(all(x)),x.end()) #define TFU(s) transform(all(s),begin(s),::toupper);//大文字にする #define TFL(s) transform(all(s),begin(s),::tolower);//小文字にする #define replace(s,a,A) replace(s,'a','A')//str(s)のaをAにする #define ROT(s,i) rotate(s.begin(),s.begin()+i,s.end())//sのi番目から後ろを前にする #define PQ priority_queue #define PQD PQ,greater

>//小さい順に吐く #define PQS PQ>//小さい順に吐く #define fi first #define se second #define bit(n,k) ((n>>k)&1LL) #define printd(n,x) cout<>a[i];} #define popcount(n) __builtin_popcountll(n) 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;} typedef vector vec; typedef vector mat; //const ll mod = 1000000009; const ll mod = 998244353; //const ll mod = 1000000007; const auto INF = (1LL<<(60)); ll modpow(ll a,ll n,ll mod){if(mod==1)return 0;ll ret=1;ll p=a%mod;while(n){if(n&1)ret=ret*p%mod;p=p*p%mod;n>>=1;}return ret; } M factor(ll n) {M ret;for(ll i=2;i*i<=n;i++){while(n%i==0){ret[i]++;n /= i;}}if(n != 1){ret[n]=1;}return ret;}//素因数分解 vec divisor(ll n){vec K;for(ll i=1;i*i<=n;i++){if(n%i==0){K.pb(i);if(i*i!=n)K.pb(n/i);}}sort(all(K));return K;}//約数列挙 ll dx[4]={0,1,0,-1},dy[4]={-1,0,1,0}; int main(){ tatananonano(); LL(n,m); vector s(n); rep(i,n){cin>>s[i];} vector

w,b; rep(i,n){ rep(j,m){ if(s[i][j]=='w'){w.pb({i,j});} if(s[i][j]=='b'){b.pb({i,j});} } } mf_graph mf(n*m+2); rep(i,w.size()){mf.add_edge(n*m,(w[i].fi*m)+w[i].se,1);} rep(i,b.size()){mf.add_edge((b[i].fi*m)+b[i].se,n*m+1,1);} rep(i,w.size()){ auto [u,v]=w[i]; rep(j,4){ if(0<=min(u+dx[j],v+dy[j]) and u+dx[i]