Fired
Time limit1sMemory limit256 MB
Choose one employee to fire so the cascade of staff left with no managers saves at least C with the smallest excess, breaking ties by larger number.
- Level
Medium6 of 10
- Topics
- Graph, BFS, Simulation
- Solved
- No attempts yet
Problem
Charlie is the head of HR at a large company. Every employee except the CEO reports to one or more people. Nobody reports to themselves, directly or indirectly.
This year's budget arrived and the salary line was cut by dollars. Charlie does not like firing people, so he wrote a program that automatically fires any employee left with nobody to report to. The program repeats until no employee other than the CEO is without a manager. It never fires the CEO automatically, even though the CEO reports to nobody.
Charlie will fire exactly one person by hand and let the program handle the rest. The total salary of everyone fired has to be at least dollars, and among the choices that reach it has to be as close to as possible. If several employees produce the same total, pick the one with the largest employee number. A CEO can be incompetent too, so Charlie may fire the CEO.
Input
The first line contains one integer , the number of test cases.
Each test case begins with a line containing two integers and , the number of employees and the amount to save.
The next lines describe employees through in order. The line for employee starts with the salary and the number of people that employee reports to, followed by numbers , the employee numbers of those people.
- , and exactly one employee has .
Output
For each test case, print on its own line the employee number of the person Charlie should fire.