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: def examC():
      N, M = LI()
      S = SI()
      V = [[] for _ in range(N)]
      ok = [1] * N
      acnt = [0] * N
      bcnt = [0] * N
      for _ in range(M):
          a, b = LI()
          V[a - 1].append(b - 1)
          V[b - 1].append(a - 1)
          if S[a - 1] == "A":
              acnt[b - 1] += 1
          else:
              bcnt[b - 1] += 1
          if S[b - 1] == "A":
              acnt[a - 1] += 1
          else:
              bcnt[a - 1] += 1
      NGque = deque()
      for i in range(N):
          if acnt[i] == 0 or bcnt[i] == 0:
              ok[i] = 0
              NGque.append(i)
      #    print(ok,acnt,bcnt)
      #    print(NGque)
      while NGque:
          cur = NGque.pop()
          for i in V[cur]:
              if ok[i] == 1:
                  if S[cur] == "A":
                      acnt[i] -= 1
                  else:
                      bcnt[i] -= 1
                  if acnt[i] == 0 or bcnt[i] == 0:
                      ok[i] = 0
                      NGque.append(i)
      if max(ok) == 1:
          ans = "Yes"
      else:
          ans = "No"
      print(ans)
  
  
  import sys, copy, bisect, itertools, math
  from heapq import heappop, heappush, heapify
  from collections import Counter, defaultdict, deque
  
  
  def I():
      return int(sys.stdin.readline())
  
  
  def LI():
      return list(map(int, sys.stdin.readline().split()))
  
  
  def LS():
      return sys.stdin.readline().split()
  
  
  def SI():
      return sys.stdin.readline().strip()
  
  
  mod = 10**9 + 7
  inf = float("inf")
  
  examC()
  
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"}]