Binary Robots
Time limit1sMemory limit128 MB
Assign each chosen robot to one distinct job it can do, with at most two jobs per robot, to maximize total rental price.
- Level
Medium6 of 10
- Topics
- Greedy, Graph, Union-find, Sorting
- Solved
- No attempts yet
Problem
The hottest product on the robot market right now is the "binary robot". A binary robot is always designed so that it can perform two kinds of work (for example sewing and unstitching, or eating and philosophizing), but it can never do both at the same time. Rarely, because of a hardware fault, a robot is able to perform only a single kind of work.
Bajtazar runs a company that rents out binary robots. He owns robots; each robot has a fixed set of jobs it can perform and a rental price . Bajtazar has received rental requests, each for a different job. When a robot is rented out it takes on exactly one of the jobs it is able to do, and each job (request) may be assigned to at most one robot. Bajtazar does not have to rent out every robot, nor accept every request.
Every robot that is rented out earns its rental price. Write a program that computes the maximum total revenue Bajtazar can earn.
Input
The first line contains three integers , , (, ): the number of robots, the number of jobs (requests) to be done, and the total number of robot skills, respectively. Robots are numbered from to and jobs from to .
The second line contains integers (), the rental price of each robot.
Each of the following lines contains two integers , (, ), meaning that robot can perform job . No pair appears more than once. Moreover, for every a pair of the form appears exactly once or twice; that is, every robot can perform one or two jobs.
Output
Print a single integer: the maximum total revenue Bajtazar can earn.