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: #!/usr/bin/env python3
  # %% for atcoder uniittest use
  import sys
  
  input = lambda: sys.stdin.readline().rstrip()
  
  
  def pin(type=int):
      return map(type, input().split())
  
  
  def tupin(t=int):
      return tuple(pin(t))
  
  
  # %%code
  def resolve():
      N, M = pin()
      lang = [set() for i in range(M)]
      for i in range(N):
          k, *l = pin()
          for j in l:
              lang[j - 1].add(i)
          # print(l)
          # print(lang)
          temp = set()
  
      way = [set() for i in range(N)]
      for sp in lang:
          if len(sp) < 2:
              continue
          for x in sp:
              way[x] = way[x].union(sp)
      # print(way)
  
      # dfs
      cond = 0
      stack = [0]
      for xyz in range(10**6):
          if stack == []:
              break
  
          temp = stack.pop()
          if temp == N - 1:
              cond = 1
              break
          for w in way[temp]:
              if w == temp:
                  continue
              stack.append(w)
      print(["NO", "YES"][cond])
  
  
  # %%submit!
  resolve()
  
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."}]