#P3005. Trough Deduction Puzzle
Trough Deduction Puzzle
Trough Deduction Puzzle
Farmer John has hidden (n) troughs ((1\le n\le20)) behind the barn, and some of them are filled with food. Bessie asks (m) questions ((1\le m\le100)) of the form: "How many troughs among the following indices are filled?" Each query gives a list of trough indices and an integer answer indicating the number of filled troughs in that list. Given all the responses, determine which troughs contain food.
For example, consider (n=4) troughs and the following queries:
- Query: troughs [1] → answer: 1
- Query: troughs [2, 3] → answer: 1
- Query: troughs [1, 4] → answer: 1
- Query: troughs [3, 4] → answer: 1
From these, we deduce: trough 1 is filled (from query 1). Then, trough 4 must be empty (from query 3) and trough 3 is filled (from query 4). Finally, trough 2 is empty (from query 2).
inputFormat
The first line contains two integers (n) and (m).
Each of the next (m) lines describes a query. A query begins with an integer (k) (the number of troughs in the query), followed by (k) integers specifying the trough indices, and ends with an integer representing the answer (the number of filled troughs in that list).
outputFormat
Output a single line with (n) integers. The (i)-th integer should be 1 if trough (i) is filled and 0 if it is empty.
sample
4 4
1 1 1
2 2 3 1
2 1 4 1
2 3 4 1
1 0 1 0