output_description: If Nusook can make all strings consisting of `A` and `B`, print `Yes`;
  otherwise, print `No`.
  
  * * *
input_description: Input is given from Standard Input in the following format:
  
      
      
      N M
      s
      a_1 b_1
      :
      a_{M} b_{M}
attempt: import sys
  sys.setrecursionlimit(1000000).
  def have_loop(G, V):
      #Gに閉路があるかを判定 Gは隣接グラフによる表現. 0-based Vは頂点数
      status = [0] * V #0 = 未訪問　1 = 訪問中 2 = 訪問済
      def visit(n):
          if status[n] == 1:
              print('Yes')
              exit()
          elif status[n] == 0:
              status[n] = 1
              for v in G[n]:
                  visit(v)
              status[n] = 2
          return None
      for v in range(V):
          visit(v)
      print('No')
      return None
  
  
  N, M = map(int, input().split())
  s = input()
  G = [[] for _ in range(2 * N)]
  for _ in range(M):
      a, b = map(lambda x: int(x) - 1, input().split())
      if s[a] == s[b]:
          G[a].append(b + N)
          G[b].append(a + N)
      else:
          G[a + N].append(b)
          G[b + N].append(a)
  
  have_loop(G, 2 * N)
  
problem_description: Statement
  
  You are given an undirected graph consisting of N vertices and M edges. The
  vertices are numbered 1 to N, and the edges are numbered 1 to M. In addition,
  each vertex has a label, `A` or `B`. The label of Vertex i is s_i. Edge i
  bidirectionally connects vertex a_i and b_i.
  
  The phantom thief Nusook likes to choose some vertex as the startpoint and
  traverse an edge zero or more times. Today, he will make a string after
  traveling as above, by placing the labels of the visited vertices in the order
  visited, beginning from the startpoint.
  
  For example, in a graph where Vertex 1 has the label `A` and Vertex 2 has the
  label `B`, if Nusook travels along the path 1 \rightarrow 2 \rightarrow 1
  \rightarrow 2 \rightarrow 2, the resulting string is `ABABB`.
  
  Determine if Nusook can make all strings consisting of `A` and `B`.
samples: [{"input": "2 3\n    AB\n    1 1\n    1 2\n    2 2", "output": "Yes\n    \n\n  * Since Nusook can visit Vertex 1 and Vertex 2 in any way he likes, he can make all strings consisting of `A` and `B`.\n\n![77e96cf8e213d606ddd8f3c3f8315d32.png](https://img.atcoder.jp/agc027/77e96cf8e213d606ddd8f3c3f8315d32.png)\n\n* * *"}, {"input": "4 3\n    ABAB\n    1 2\n    2 3\n    3 1", "output": "No\n    \n\n  * For example, Nusook cannot make `BB`.\n  * The given graph may not be connected.\n\n![1ab1411cb9d6ee023d14ca4e77c4b584.png](https://img.atcoder.jp/agc027/1ab1411cb9d6ee023d14ca4e77c4b584.png)\n\n* * *"}, {"input": "13 23\n    ABAAAABBBBAAB\n    7 1\n    10 6\n    1 11\n    2 10\n    2 8\n    2 11\n    11 12\n    8 3\n    7 12\n    11 2\n    13 13\n    11 9\n    4 1\n    9 7\n    9 6\n    8 13\n    8 6\n    4 10\n    8 7\n    4 3\n    2 1\n    8 12\n    6 9", "output": "Yes\n    \n\n* * *"}, {"input": "13 17\n    BBABBBAABABBA\n    7 1\n    7 9\n    11 12\n    3 9\n    11 9\n    2 1\n    11 5\n    12 11\n    10 8\n    1 11\n    1 8\n    7 7\n    9 10\n    8 8\n    8 12\n    6 2\n    13 11", "output": "No"}]