Cookie Run: Kingdom
Time limit1sMemory limit512 MB
Given which resource types each building produces and which resources each unbuilt building needs, count the buildings constructible within T seconds starting from the M already-built ones.
- Level
Medium6 of 10
- Topics
- Graph, BFS, Hash map, Simulation
- Solved
- No attempts yet
Problem
My friend Brave Cookie is troubled. These days Brave Cookie plays a game called Cookie Run: Kingdom, where buildings are constructed using some of the kinds of resources numbered . A resource can be produced without cost and without limit through buildings that are already built, and the building that can produce each resource is fixed. Producing a resource takes seconds, building a building takes second, and multiple resources can be produced or buildings built at the same time. The maximum number of kinds of resources each building requires and can produce is the smaller of and (= ).
Brave Cookie wonders which buildings can be constructed within a given time using the buildings that are already built, and wants to know quickly. But Brave Cookie is too busy to figure it out. Let us help my friend Brave Cookie right away. A building that is already built also counts as a building that can be constructed within the given time.
Input
The first line gives the number of kinds of resources , the number of buildings already built , and the time limit . The number of kinds of buildings equals the number of kinds of resources, . Both buildings and resources are numbered from to .
The second line gives distinct numbers, which are the numbers of the buildings already built.
Then lines follow, each giving a building's number of producible resource kinds and those resource numbers, separated by spaces.
After that, lines follow, each giving the number of a building not yet built, the number of resource kinds that building requires, and those resource numbers, separated by spaces.
Here, the number of resources each building produces and the number of resource kinds required to build a building is at least .
The maximum number of kinds of resources each building requires and can produce does not exceed and , that is, it is at most .
Output
On the first line, print the number of buildings that can be built within seconds. On the second line, print the numbers of all buildings that can be built within the time limit in ascending order, separated by spaces.