Odd Loving Bakers
Time limit1sMemory limit128 MB
Simulate monthly celebrations where bakers with an odd chalk count win and add marks to their favorite bakers; find the number of winners at celebration t up to 1e9.
- Level
Medium7 of 10
- Topics
- Bit manipulation, Math, Graph, Simulation
- Solved
- No attempts yet
Problem
A town has bakers. Every month they hold a celebration and award a prize to some of them, chosen as follows.
At the start, chalk marks are drawn on the houses of some bakers. Each baker keeps a list of favorite bakers. Right before each celebration, every baker whose house currently has an odd number of chalk marks becomes a winner of that celebration. Immediately after the celebration, each winner adds one chalk mark to the house of every baker on their own favorite list.
Given the initial chalk marks and every baker's favorite list, determine how many winners the -th celebration has.
Input
The first line contains an integer (), the number of test cases. Each test case has the following form:
- The first line contains two integers and : the number of bakers, and the index of the celebration whose winners must be counted.
- Each of the next lines describes one baker: the baker's name (a lowercase string of at most 20 characters with no spaces), then the number of chalk marks initially on that baker's house, then the number of bakers on that baker's favorite list, followed by those bakers' names.
Output
For each test case, print a single line with one integer: the number of winners of the -th celebration.
Constraints
- the initial number of chalk marks on a baker's house