Vasya wants to turn on Christmas lights consisting of m bulbs. Initially, all bulbs are turned off. There are n buttons, each of them is connected to some set of bulbs. Vasya can press any of these buttons. When the button is pressed, it turns on all the bulbs it's connected to. Can Vasya light up all the bulbs?
If Vasya presses the button such that some bulbs connected to it are already turned on, they do not change their state, i.e. remain turned on.
Input
The first line of the input contains integers n and m (1 ≤ n, m ≤ 100) — the number of buttons and the number of bulbs respectively.
Each of the next n lines contains xi (0 ≤ xi ≤ m) — the number of bulbs that are turned on by the i-th button, and then xi numbers yij (1 ≤ yij ≤ m) — the numbers of these bulbs.
Output
If it's possible to turn on all m bulbs print "YES", otherwise print "NO".
Examples
Input
3 4
2 1 4
3 1 3 1
1 2
Output
YES
Input
3 3
1 1
1 2
1 1
Output
NO
Note
In the first sample you can press each button once and turn on all the bulbs. In the 2 sample it is impossible to turn on the 3-rd lamp.
Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
We are asked: Given n buttons, each turns on a set of bulbs (subset of {1..m}). Initially all bulbs off. Pressing a button turns on all bulbs in its set (if already on, stays on). Can we turn on all m bulbs? Essentially, is the union of the sets of bulbs covered by some selection of buttons equal to all bulbs? Since pressing a button multiple times does nothing extra (it just turns on bulbs, duplicates don't hurt). So the condition is: the union of all buttons' sets must cover all bulbs. Because we can press all buttons. However, careful: Is there any nuance? The problem statement: "Vasya can press any of these buttons. When the button is pressed, it turns on all the bulbs it's connected to." It does not say that pressing a button toggles or anything; it just turns on. So pressing any set of buttons (including all) yields the union of their sets. So the condition to light all bulbs is simply: the union of all button sets = {1..m}. That's it. Check the examples:
Example 1:
3 4
2 1 4 -> set {1,4}
3 1 3 1 -> set {1,3} (they gave 1 3 1, duplicates but effectively {1,3})
1 2 -> set {2}
Union = {1,2,3,4} => YES.
Thus the answer is straightforward. But wait: there might be a trick? Could pressing only some subset be necessary? No because pressing more can't hurt. Unless there is some button that turns off bulbs? Not described. So pressing all buttons always yields union. So the answer is YES if the union of all button sets covers all bulbs, otherwise NO.
Thus algorithm: Read n,m. Initialize boolean array bulb[1..m] = false. For each i from 1..n: read xi, then for j from 1..xi: read y, bulb[y] = true. After reading all, check if all bulb[1..m] are true. Print YES or NO accordingly.
But careful: The problem says each line contains xi and then xi numbers. xi can be 0. If xi=0, then no bulbs are turned on by that button. So the union may not cover some bulbs. That's fine.
Thus code is simple.
We must output exactly "YES" or "NO".
Implementation details: Input constraints up to 100, so trivial.
Thus final answer: print "YES" if all bulbs are covered, else "NO".
We'll produce the solution in the asked format.
Make sure to use appropriate language: The user likely expects a solution in Python or similar. I'll write a clear solution.
Also note: The problem title suggests "Chat room"? Actually "bulbs" but whatever.
I'll produce a Python solution.
Potential pitfalls: There may be duplicates, but setting boolean handles it.
Time complexity O(n*m) essentially.
We'll write code:
def solve():
import sys
data = sys.stdin.read().strip().split()
if not data: return
it = iter(data)
n = int(next(it))
m = int(next(it))
bulbs = [False]*(m+1)
for _ in range(n):
xi = int(next(it))
for __ in range(xi):
y = int(next(it))
bulbs[y] = True
if all(bulbs[1:]):
print("YES")
else:
print("NO")
That's it.
But also need to consider the case where m=0? According to constraints m≥1.
Edge case: n=0? n≥1 per constraints.
Thus fine.
Now output final answer: Provide explanation and code.
Since the user asked: "Write the solution in python with required method signature? Not required. Provide solution.
Thus answer: Provide code. ```python
import sys
def solve() -> None:
data = sys.stdin.read().strip().split()
if not data:
return
it = iter(data)
n = int(next(it))
m = int(next(it))
code
# bulbs[1..m] initialized to False (off)
bulbs = [False] * (m + 1)
for _ in range(n):
xi = int(next(it))
for __ in range(xi):
y = int(next(it))
bulbs[y] = True # this bulb can be turned on
# check if every bulb 1..m can be turned on
if all(bulbs[1:]):
print("YES")
else:
print("NO")