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: import sys
  
  stdin = sys.stdin
  
  ri = lambda: int(rs())
  rl = lambda: list(map(int, stdin.readline().split()))  # applies to numbers only
  rs = lambda: stdin.readline().rstrip()  # ignores trailing space
  
  # 人は0からN-1,言語は1からMまで
  N, M = rl()
  KL = [rl() for _ in range(N)]
  speak_lan = [[] for _ in range(M + 1)]  # 0は使わない
  for i, x in enumerate(KL):
      k, *lan = x
      for l in lan:
          speak_lan[l].append(i)
  
  communicate = set()
  
  
  def dfs(person):
      global communicate
      lan = KL[person][1:]
      for l in lan:
          for p in speak_lan[l]:
              if p not in communicate:
                  communicate.add(p)
                  dfs(p)
  
  
  dfs(0)
  if len(communicate) == N:
      print("YES")
  else:
      print("NO")
  
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."}]