#pragma GCC optimize("Ofast") #include #include using namespace std; using namespace atcoder; typedef long long int ll; typedef unsigned long long ull; mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); ll myRand(ll B) { return (ull)rng() % B; } // N使ってる状態 0 // M使ってる状態 1 int main(){ cin.tie(nullptr); ios::sync_with_stdio(false); int n,m; cin >> n >> m; vector> a(n,vector(m)); map>> mp; for(int i=0;i> a[i][j]; mp[a[i][j]].push_back({i,j}); } } int res=0; for(auto p:mp){ if(p.first==0)continue; vector v,vv; for(auto pp:p.second){ v.push_back(pp.first); vv.push_back(pp.second); } sort(v.begin(), v.end()); sort(vv.begin(), vv.end()); v.erase(unique(v.begin(), v.end()),v.end()); vv.erase(unique(vv.begin(), vv.end()),vv.end()); int N=v.size(),M=vv.size(); mf_graph g(N+M+2); int S=N+M,T=N+M+1; for(int i=0;i