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

K = []

L = []

for _ in range(N):

    k,*l = list(map(int,input().split()))

    K.append(k)

    L.append(l)

    

graph = [[] for _ in range(N+M)]

for i in range(N):

    for l in L[i]:

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

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



visited = [0 for _ in range(N+M)]

visited[0] = 1

stack = [0]



while stack:

    node = stack.pop()

    for adj in graph[node]:

        if not visited[adj]:

            visited[adj] = 1

            stack.append(adj)

            

print(('YES' if all(visited[:N]) else 'NO'))
class UnionFind():

    def __init__(self, n):

        self.n = n

        self.parents = [i for i in range(n)]

        self.size = [1 for _ in range(n)]



    def find(self, x):

        root = x

        while self.parents[root] != root:

            root = self.parents[root]

        return root



    def unite(self, x, y):

        xroot = self.find(x)

        yroot = self.find(y)

        if xroot == yroot: return

        if self.size[xroot] <= self.size[yroot]:

            self.parents[xroot] = yroot

            self.size[yroot] += self.size[xroot]

        else:

            self.parents[yroot] = xroot

            self.size[xroot] += self.size[yroot]



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



uf = UnionFind(M)

L = []



for _ in range(N):

    k, *l = list(map(int, input().split()))

    for i in range(1, k):

        uf.unite(l[0] - 1, l[i] - 1)

    L.append(l[0] - 1)



if len(set([uf.find(L[i]) for i in range(N)])) == 1:

    print('YES')

else:

    print('NO')
N, M = list(map(int, input().split()))
K = []
L = []
for _ in range(N):
    k, *l = list(map(int, input().split()))
    K.append(k)
    L.append(l)
graph = [[] for _ in range(N + M)]
for i in range(N):
    for l in L[i]:
        graph[i].append(N + l - 1)
        graph[N + l - 1].append(i)
visited = [0 for _ in range(N + M)]
visited[0] = 1
stack = [0]
while stack:
    node = stack.pop()
    for adj in graph[node]:
        if not visited[adj]:
            visited[adj] = 1
            stack.append(adj)
print(("YES" if all(visited[:N]) else "NO"))

class UnionFind:
    def __init__(self, n):
        self.n = n
        self.parents = [i for i in range(n)]
        self.size = [1 for _ in range(n)]

    def find(self, x):
        root = x
        while self.parents[root] != root:
            root = self.parents[root]
        return root

    def unite(self, x, y):
        xroot = self.find(x)
        yroot = self.find(y)
        if xroot == yroot:
            return
        if self.size[xroot] <= self.size[yroot]:
            self.parents[xroot] = yroot
            self.size[yroot] += self.size[xroot]
        else:
            self.parents[yroot] = xroot
            self.size[xroot] += self.size[yroot]


N, M = list(map(int, input().split()))
uf = UnionFind(M)
L = []
for _ in range(N):
    k, *l = list(map(int, input().split()))
    for i in range(1, k):
        uf.unite(l[0] - 1, l[i] - 1)
    L.append(l[0] - 1)
if len(set([uf.find(L[i]) for i in range(N)])) == 1:
    print("YES")
else:
    print("NO")

+class UnionFind: +    def __init__(self, n): +        self.n = n +        self.parents = [i for i in range(n)] +        self.size = [1 for _ in range(n)] + +    def find(self, x): +        root = x +        while self.parents[root] != root: +            root = self.parents[root] +        return root + +    def unite(self, x, y): +        xroot = self.find(x) +        yroot = self.find(y) +        if xroot == yroot: +            return +        if self.size[xroot] <= self.size[yroot]: +            self.parents[xroot] = yroot +            self.size[yroot] += self.size[xroot] +        else: +            self.parents[yroot] = xroot +            self.size[xroot] += self.size[yroot] + + -K = [] +uf = UnionFind(M) -    K.append(k) -    L.append(l) -graph = [[] for _ in range(N + M)] -for i in range(N): -    for l in L[i]: -        graph[i].append(N + l - 1) -        graph[N + l - 1].append(i) -visited = [0 for _ in range(N + M)] -visited[0] = 1 -stack = [0] -while stack: -    node = stack.pop() -    for adj in graph[node]: -        if not visited[adj]: -            visited[adj] = 1 -            stack.append(adj) -print(("YES" if all(visited[:N]) else "NO")) +    for i in range(1, k): +        uf.unite(l[0] - 1, l[i] - 1) +    L.append(l[0] - 1) +if len(set([uf.find(L[i]) for i in range(N)])) == 1: +    print("YES") +else: +    print("NO")