Balanced Job Assignment
Time limit4sMemory limit256 MB
Assign every matchable job to exactly one qualified worker so that the job counts per worker are as close as possible to M/N in Euclidean distance.
- Level
Medium7 of 10
- Topics
- Graph, Shortest path
- Solved
- No attempts yet
Problem
There are workers and different jobs. You are given a matrix , where if worker is qualified to complete job , and otherwise. A worker can be assigned to a job only if they are qualified for it.
Assign workers to jobs so that the distribution of the number of jobs done by each worker is as close as possible to uniform, measured by Euclidean distance. That is, the -dimensional vector whose -th element is the number of jobs done by worker should be as close as possible to the -dimensional vector whose every element is the real number .
Each job that can be completed by at least one worker must be assigned to exactly one worker.
Input
The first line contains two integers and (). The next lines each contain characters, either '0' or '1'. These lines describe the matrix .
Output
Print lines. On line , first print , the number of jobs assigned to worker . Then print the numbers of those jobs. If several assignments give an optimal distribution, you may print any of them.
Hint
The Euclidean distance between two vectors and is