N,M = list(map(int,input().split()))

KL = [list(map(int,input().split())) for _ in [0]*N ]



E = [[[] for _ in [0]*N] , [[] for _ in [0]*M]]

for i,kl in enumerate(KL):

    for l in kl[1:]:

        E[0][i].append(l-1)

        E[1][l-1].append(i)



Check = [[False]*N,[False]*M]

Check[0][0] = True

q = [[0,0]]

while q:

    cl,i = q.pop()

    for j in E[cl][i]:

        if Check[1-cl][j]:continue

        q.append([1-cl,j])

        Check[1-cl][j] = True



if sum(Check[0]) == N:

    print("YES")

else:

    print("NO")
#二部グラフで連結判定

N,M = list(map(int,input().split()))

KL = [list(map(int,input().split())) for _ in [0]*N]



c = [False]*(N+M) #d[0] - d[N-1]:人, d[N] - D[N+M-1]:言語

E = [[] for _ in [0]*(N+M)]

for i,kl in enumerate(KL):

    for l in kl[1:]:

        E[i].append(N+l-1)

        E[N+l-1].append(i)



start = 0

q = [start]

c[start] = True

while q:

    i = q.pop()

    for j in E[i]:

        if c[j]:continue

        c[j] = True

        q.append(j)



ans = True

for b in c[:N]:

    ans = ans and b

print(("YES" if ans else "NO"))
N, M = list(map(int, input().split()))
KL = [list(map(int, input().split())) for _ in [0] * N]
E = [[[] for _ in [0] * N], [[] for _ in [0] * M]]
for i, kl in enumerate(KL):
    for l in kl[1:]:
        E[0][i].append(l - 1)
        E[1][l - 1].append(i)
Check = [[False] * N, [False] * M]
Check[0][0] = True
q = [[0, 0]]
while q:
    cl, i = q.pop()
    for j in E[cl][i]:
        if Check[1 - cl][j]:
            continue
        q.append([1 - cl, j])
        Check[1 - cl][j] = True
if sum(Check[0]) == N:
    print("YES")
else:
    print("NO")

# 二部グラフで連結判定
N, M = list(map(int, input().split()))
KL = [list(map(int, input().split())) for _ in [0] * N]
c = [False] * (N + M)  # d[0] - d[N-1]:人, d[N] - D[N+M-1]:言語
E = [[] for _ in [0] * (N + M)]
for i, kl in enumerate(KL):
    for l in kl[1:]:
        E[i].append(N + l - 1)
        E[N + l - 1].append(i)
start = 0
q = [start]
c[start] = True
while q:
    i = q.pop()
    for j in E[i]:
        if c[j]:
            continue
        c[j] = True
        q.append(j)
ans = True
for b in c[:N]:
    ans = ans and b
print(("YES" if ans else "NO"))

+# 二部グラフで連結判定 -E = [[[] for _ in [0] * N], [[] for _ in [0] * M]] +c = [False] * (N + M)  # d[0] - d[N-1]:人, d[N] - D[N+M-1]:言語 +E = [[] for _ in [0] * (N + M)] -        E[0][i].append(l - 1) -        E[1][l - 1].append(i) -Check = [[False] * N, [False] * M] -Check[0][0] = True -q = [[0, 0]] +        E[i].append(N + l - 1) +        E[N + l - 1].append(i) +start = 0 +q = [start] +c[start] = True -    cl, i = q.pop() -    for j in E[cl][i]: -        if Check[1 - cl][j]: +    i = q.pop() +    for j in E[i]: +        if c[j]: -        q.append([1 - cl, j]) -        Check[1 - cl][j] = True -if sum(Check[0]) == N: -    print("YES") -else: -    print("NO") +        c[j] = True +        q.append(j) +ans = True +for b in c[:N]: +    ans = ans and b +print(("YES" if ans else "NO"))