#include #include #include #include #include using namespace std; using namespace atcoder; int a[510][510]; map mp1[510]; map mp2[510]; int main(){ int i,j,h,w; cin >> h >> w; int now = 0; for(i=0;i> a[i][j]; if(a[i][j]==0) continue; if(mp1[i].find(a[i][j])==mp1[i].end()){ mp1[i][a[i][j]] = now; now++; } if(mp2[j].find(a[i][j])==mp2[j].end()){ mp2[j][a[i][j]] = now; now++; } } } mf_graph g(now + 2); int s = now,t = now + 1; for(i=0;i