const int MAX = 1e6+10; const int inf = 0x3f3f3f3f; int n,m; int lx[MAX],ly[MAX]; int match[MAX]; int usex[MAX],usey[MAX]; int w[MAX][MAX]; int find(int u) { usex[u]=1; for(int i=0;i<m;i++) { if(!usey[i]&&w[u][i]==ly[i]+lx[u]) { usey[i]=1; if(match[i]==-1||find(match[i])) { match[i]=u; return true; } } } return false; }