#include <bits/stdc++.h>
// Make a function to check job available for that student or not
bool isJob(int id, vector<vector<int>>& mat, vector<int>& jobAlloted, vector<bool> check, int n){
// Iterate over each job for this student
for(int i=0; i<n; i++){
// Check student job eligibility and already no job
if(mat[id][i]==1 && !check[i]){
check[i] = true; // allot job
// if that job not alloted to anyone or if alloted, other job for that student available or not
if(jobAlloted[i] == -1 || isJob(jobAlloted[i], mat, jobAlloted, check, n)){
jobAlloted[i]=id;
return true;
}
}
}
return false;
}
int maxMatch(vector<vector<int> > &mat) {
int m = mat.size(), n = mat[0].size();
// Number of job is fixed, to store which job corr. to which student
vector<int> jobAlloted(n,-1);
int jobCount = 0;
// Iterate over each student to allot a job
for(int i=0; i<m; i++){
vector<bool> check(n, false);
if(isJob(i, mat, jobAlloted, check, n)){
jobCount++;
}
}
return jobCount;
}



