output_description: If there exists a graph that matches Snuke's memory, print `Yes`; otherwise,
  print `No`.
  
  * * *
input_description: Input is given from Standard Input in the following format:
  
      
      
      N M Q
      A_0 B_0 C_0
      A_1 B_1 C_1
      \vdots
      A_{Q-1} B_{Q-1} C_{Q-1}
attempt: N, M, Q = [int(_) for _ in input().split()]
  Info0 = []
  Info1 = []
  for _ in range(Q):
      a, b, c = [int(_) for _ in input().split()]
      if c:
          Info1 += [(a, b)]
      else:
          Info0 += [(a, b)]
  
  size = N
  UF = list(range(size))
  SIZE = [1] * size  # 0-indexed
  
  
  def find(x):
      stack = [x]
      while True:
          y = stack[-1]
          if UF[y] != y:
              stack += [UF[y]]
          else:
              break
      for s in stack:
          UF[s] = y
      return y
  
  
  def unite(x, y):
      if not is_same(x, y):
          X, Y = find(x), find(y)
          SX, SY = SIZE[X], SIZE[Y]
          if SX > SY:
              m = UF[X] = Y
          else:
              m = UF[Y] = X
          SIZE[m] = SX + SY
          SIZE[X + Y - m] = 0
  
  
  def is_same(x, y):
      return find(x) == find(y)
  
  
  def scan_uf():
      length = len(UF)
      for i in range(length):
          find(i)
  
  
  for a, b in Info0:
      if is_same(a, b):
          print("No")
          exit()
      else:
          unite(a, b)
  if len(Info1) == 0:
      print("Yes")
      exit()
  for a, b in Info1:
      if is_same(a, b):
          print("No")
          exit()
      else:
          unite(a, b)
  scan_uf()
  print("Yes" if len(set(UF)) > 1 else "No")
  
problem_description: Statement
  
  Snuke's mother gave Snuke an undirected graph consisting of N vertices
  numbered 0 to N-1 and M edges. This graph was connected and contained no
  parallel edges or self-loops.
  
  One day, Snuke broke this graph. Fortunately, he remembered Q clues about the
  graph. The i-th clue (0 \leq i \leq Q-1) is represented as integers
  A_i,B_i,C_i and means the following:
  
    * If C_i=0: there was exactly one simple path (a path that never visits the same vertex twice) from Vertex A_i to B_i.
    * If C_i=1: there were two or more simple paths from Vertex A_i to B_i.
  
  Snuke is not sure if his memory is correct, and worried whether there is a
  graph that matches these Q clues. Determine if there exists a graph that
  matches Snuke's memory.
samples: [{"input": "5 5 3\n    0 1 0\n    1 2 1\n    2 3 0", "output": "Yes\n    \n\nFor example, consider a graph with edges (0,1),(1,2),(1,4),(2,3),(2,4). This\ngraph matches the clues.\n\n* * *"}, {"input": "4 4 3\n    0 1 0\n    1 2 1\n    2 3 0", "output": "No\n    \n\n* * *"}, {"input": "10 9 9\n    7 6 0\n    4 5 1\n    9 7 0\n    2 9 0\n    2 3 0\n    4 1 0\n    8 0 0\n    9 1 0\n    3 0 0", "output": "No"}]