For each boy from to , call with a fresh visited array. The DFS tries to match boy to some girl in his adjacency list. If girl is currently unmatched, set match[j] = i and return true.
If is matched to boy , recursively try to rematch to a different girl. If that succeeds, take for yourself. Count how many boys successfully match. This count is your answer.
This runs in time and uses space.