output_description: If all N participants can communicate with all other participants, print
  `YES`. Otherwise, print `NO`.
  
  * * *
input_description: The input is given from Standard Input in the following format:
  
      
      
      N M
      K_1 L_{1,1} L_{1,2} ... L_{1,{}K_1}
      K_2 L_{2,1} L_{2,2} ... L_{2,{}K_2}
      :
      K_N L_{N,1} L_{N,2} ... L_{N,{}K_N}
attempt: class UnionFind:
      def __init__(self, n):
          self.n = n
          self.p = [e for e in range(n)]
          self.rank = [0] * n
          self.size = [1] * n
  
      def same(self, u, v):
          return self.find_set(u) == self.find_set(v)
  
      def unite(self, u, v):
          u = self.find_set(u)
          v = self.find_set(v)
  
          if u == v:
              return
  
          if self.rank[u] > self.rank[v]:
              self.p[v] = u
              self.size[u] += self.size[v]
          else:
              self.p[u] = v
              self.size[v] += self.size[u]
              if self.rank[u] == self.rank[v]:
                  self.rank[v] += 1
  
      def find_set(self, u):
          if u != self.p[u]:
              self.p[u] = self.find_set(self.p[u])
  
          return self.p[u]
  
      def update_p(self):
          for u in range(self.n):
              self.find_set(u)
  
      def get_size(self, u):
          return self.size[self.find_set(u)]
  
  
  n, m = map(int, input().split())
  l = []
  for _ in range(n):
      k, *ls = map(int, input().split())
      l.append(ls)
  
  uf = UnionFind(m)
  
  for li in l:
      for e1, e2 in zip(li, li[1:]):
          e1 -= 1
          e2 -= 1
          uf.unite(e1, e2)
  
  p = uf.find_set(l[0][0])
  ans = "YES"
  for e, *_ in l:
      e -= 1
      if uf.find_set(e) != p:
          ans = "NO"
  
  print(ans)
  
problem_description: Statement
  
  On a planet far, far away, M languages are spoken. They are conveniently
  numbered 1 through M.
  
  For _CODE FESTIVAL 20XX_ held on this planet, N participants gathered from all
  over the planet.
  
  The i-th (1≦i≦N) participant can speak K_i languages numbered L_{i,1},
  L_{i,2}, ..., L_{i,{}K_i}.
  
  Two participants A and B can _communicate_ with each other if and only if one
  of the following conditions is satisfied:
  
    * There exists a language that both A and B can speak.
    * There exists a participant X that both A and B can communicate with.
  
  Determine whether all N participants can communicate with all other
  participants.
samples: [{"input": "4 6\n    3 1 2 3\n    2 4 2\n    2 4 6\n    1 6", "output": "YES\n    \n\nAny two participants can communicate with each other, as follows:\n\n  * Participants 1 and 2: both can speak language 2.\n  * Participants 2 and 3: both can speak language 4.\n  * Participants 1 and 3: both can communicate with participant 2.\n  * Participants 3 and 4: both can speak language 6.\n  * Participants 2 and 4: both can communicate with participant 3.\n  * Participants 1 and 4: both can communicate with participant 2.\n\nNote that there can be languages spoken by no participant.\n\n* * *"}, {"input": "4 4\n    2 1 2\n    2 1 2\n    1 3\n    2 4 3", "output": "NO\n    \n\nFor example, participants 1 and 3 cannot communicate with each other."}]