#P9257. Wise Sages and Spells

    ID: 22412 Type: Default 1000ms 256MiB

Wise Sages and Spells

Wise Sages and Spells

For centuries, the mystical land of Bitoland has been inhabited by n sages and m spells. According to the ancient magical law, every spell is known by exactly \(n-2\) sages. Every sage knows, for each spell he personally knows, exactly which other sages know it. However, no sage knows the total number of spells that exist; in particular, a sage might not know any spell at all. (In that case he is unaware of whether any spell exists — though he does know that if any spell exists, exactly \(n-2\) sages will know it.)

Every day at noon the sages gather in the Stumegabyte Forest. They do not communicate with one another; they merely greet and meditate, and return to their abodes in the evening. The sages have no other means of communication.

They are bound by an ancient tradition: if a sage deduces that there exists at least one spell that he does not know, he must leave Bitoland that midnight without alerting anyone and never return.

One day a wanderer arrives in Bitoland. After observing the sages for a few days he proclaims to all: "I have noticed that at least one of you knows at least one spell!" The wanderer will remain in Bitoland for k days (at most one month) and will say nothing more.

Assuming the sages are flawless logicians and will deduce all that they can from the announcement and from their own knowledge of spells, determine whether during these k days there will be a day at the noon meeting when at least one sage is missing.

Note: A sage who knows no spells will eventually deduce (from the wanderer's announcement and the flawless reasoning of his peers) that if any spell exists then he does not know it, and so must leave. In this problem, let r be the number of sages that initially know no spell. Such sages will all leave on day r, provided that r > 0. If all sages know at least one spell then no one will ever leave.

inputFormat

The input is given as follows:

 n k
 t1 a1,1 a1,2 ... a1,t1
 t2 a2,1 a2,2 ... a2,t2
 ...
 tn an,1 an,2 ... an,tn

Here, n is the number of sages, and k is the number of days the wanderer stays.

Each of the next n lines describes one sage. The first integer in the line, ti, denotes the number of spells known by the i-th sage. If ti = 0, then the i-th sage does not know any spell. Otherwise, for each spell the i-th sage knows, he also knows exactly which other sage knows that spell — that is, for each known spell, a single integer is given denoting the unique other sage (besides himself) who does not know that spell (since every spell is known by exactly \(n-2\) sages, every spell known by the i-th sage is unknown by exactly one other sage).

You may assume that \(n \ge 3\) (so that \(n-2 \ge 1\)). The input guarantees consistency with the magical law.

outputFormat

Output a single line containing YES if there will be a day (within the k-day period) when at least one sage is absent from the noon meeting, or NO otherwise.

Explanation: Let r be the number of sages who initially know no spells. By the rules of the tradition and the impeccable reasoning of the sages, if r > 0 the sages with no spell will deduce on day r that, since the wanderer's announcement guarantees the existence of a spell, they must be lacking some spell, and will hence leave. Therefore, output YES if r > 0 and k \ge r; otherwise, output NO.

sample

3 1
1 2
1 3
0
YES