Unit Founding Event
InterviewTime limit1sMemory limit1024 MB
Order N stages so each soldier joins its first preferred stage in that order and every stage meets its minimum headcount, or report -1.
Problem
The enrollment for the unit founding event just closed!
The event consists of stages numbered through , and soldiers take part. Each soldier has picked one or more preferred stages.
For the event to succeed, every stage must reach its minimum headcount. Since there is no spare capacity to distribute soldiers carefully, first fix the order of the stages, then place on each stage the soldiers who preferred it. Every soldier joins only the preferred stage that comes first in the order.
Find an order in which the event can succeed, and print one such order.
Input
The first line contains the number of stages and the number of soldiers , separated by a space.
The second line contains the minimum headcount of each stage from stage to stage , separated by spaces.
Each of the next lines contains , the number of stages that soldier prefers, followed by the preferred stage numbers in ascending order. All numbers on a line are separated by spaces.
Output
If an order exists that meets the minimum headcount of every stage, print one valid order on lines. Otherwise, print -1.
Constraints
- ; the sum of all does not exceed .