Boss Rush
Time limit1sMemory limit256 MB
Find how many bosses from the front can each receive one allowed laser, rocket and psiotic weapon when every weapon has two copies.
- Level
Medium6 of 10
- Topics
- Graph, Binary search
- Solved
- No attempts yet
Problem
You are playing the new game Mega Man XIII-2. The boss fights are extremely hard. Your arsenal includes weapons such as the PowerLaser, the EvilRocket and the PsychTerror, and every weapon belongs to exactly one of three categories: laser, rocket and psiotic. To defeat one boss you must use three weapons, one from each category. Each boss is vulnerable only to some of the weapons, and you studied every boss in advance, so you know which weapons work against which boss.
You start the game with two copies of every weapon. The bosses appear in a fixed order. In each boss fight you choose one weapon from each category, and after the fight those three copies are worn out and cannot be used again.
Spending a weapon on an early boss can leave you stuck later, so choose carefully. Find the largest such that you can defeat bosses through in order. The game ends at the first boss you cannot defeat.
Input
The first line contains one integer , the number of test cases. Each test case begins with a line containing one integer , the number of bosses. Then groups of 3 lines follow, lines in total. The three lines of group list the laser, rocket and psiotic weapons that work against boss , in that order. Each line starts with an integer , the number of weapons in category that work against boss , followed by weapon names separated by spaces.
- Every weapon name has length 1 to 32.
- A weapon name consists of uppercase and lowercase letters a to z only.
- A weapon name always belongs to the same category.
Output
For each test case, print on one line the maximum number of bosses you can defeat.