Bipartite matching · Hard
Each waiting job can run only on certain workers because of capabilities. Assigning the first available worker greedily can leave avoidable idle capacity.
Return the maximum number of jobs that can run at once with one job per worker.
Input
Call
- Implement
solve(input)and return its result. Do not print fromsolve.
Input object
{ workers:integer, eligible:integer[][] }. eligible[i] lists worker IDs that can execute job i; repeated IDs are allowed
What each field means
workers— number of workers with IDs0throughworkers - 1.eligible[i]— worker IDs allowed to execute jobi; duplicate IDs have no extra effect.
Output
Return value and rules
- Return the maximum number of jobs that can run simultaneously.
- Assign each job to at most one eligible worker and each worker to at most one job.
- Return only the count, not a particular assignment.
Constraints
- 0 <= workers <= 200; 0 <= eligible.length <= 200
- Worker IDs are in [0,workers-1]; each eligible list contains at most 200 entries.
Examples
Example 1
{
"eligible": [
[
0,
1
],
[
0
]
],
"workers": 2
}Returns
2Example 2
{
"eligible": [],
"workers": 0
}Returns
0Required complexity
O(jobs × eligibilityEdges) time and O(workers + jobs) auxiliary space