Get to Work (Small)
Time limit5sMemory limit512 MB
Assign drivers so every employee reaches town T using the fewest cars, and report how many cars leave each town.
- Level
Medium5 of 10
- Topics
- Greedy, Simulation, Implementation
- Solved
- No attempts yet
Problem
A company has its office in town and employs people. There are towns in the area, and every employee lives in one of them.
Some employees drive. Each employee comes with an integer . If is , that employee has no license and cannot drive. If is at least , the car that employee drives holds people counting the driver, so means the driver takes only themselves to work.
The only way an employee moves between towns is in an employee's car, and an employee rides only with a driver who lives in the same town. An employee who lives in town is already in the town with the office and needs no car.
Decide whether every employee can reach town . If they can, choose the drivers so that the number of cars on the road is as small as possible, and find how many cars leave each town.
Input
The first line contains the number of test cases .
Each test case is given as follows.
- One line with the number of towns and the number of the town where the office is.
- One line with the number of employees .
- lines describing one employee each. Each line has the number of the town that employee lives in and the capacity of the car that employee drives.
, , , , , .
Output
Print one line per test case, in the order the test cases are given. Each line starts with Case #X: , where X is the number of the test case counting from . After that print one of the following.
IMPOSSIBLE, if there are not enough drivers for every employee to reach the office.- If every employee can reach the office, print integers separated by one space, the number of cars leaving town through town when the total number of cars is minimal. The value for town is always .