Investigating Imposters

아직 제출이 없습니다시간 제한1초메모리 제한1024 MB

문제

You have stumbled upon a village. In this village, some of the people are “imposters”, while the rest are not. Fortunately, you know that the number of possible imposters is limited!

You would like to determine who is not an imposter in this village. To do so, you ask each villager to submit a list of some villagers who are not imposters.

Non-imposters will only submit lists that contain other non-imposter names, while there is no such restriction for imposters. Imposters’ lists could contain imposters or non-imposters.

Given the lists of each villager, determine whether they could possibly be an imposter, or are definitely not an imposter.

입력

The first line of input contains two space-separated integers nn and kk (1kn5001 \le k \le n \le 500), where nn is the number of villagers and kk is the maximum possible number of imposters. The villagers are numbered from 1 to nn.

Each of the next nn lines describes a villager, where the iith line represents the list of villager i. The iith line starts with an integer ss (0sn0 \le s \le n), which is the number of people on villager ii’s list of non-imposters. Then there will follow s distinct integers denoting the villagers on villager ii’s list of non-imposters. It is possible for a villager to appear on their own list. All of the villagers on any given list will be distinct.

출력

Output nn lines, each with a single integer. The iith line should contain 0 if the villager represented by the iith list in the input could possibly be an imposter, and 1 if that villager is definitely not an imposter.