Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(10**6)

N,M=map( int, raw_input().split() )
S="z"+raw_input()
num=[ [ 0 for i in range(2) ] for j in range(N+1) ] 

nl= [ [] for j in range(N+1) ] 


deleted=[ 0 for j in range(N+1) ] 

for i in range(M):
	a,b=map( int, sys.stdin.readline().split() )
	if not b in nl[a]:
		nl[a].append(b)
		nl[b].append(a)
		if S[b]=="A":  num[a][0]+=1
		elif S[b]=="B":  num[a][1]+=1
		if S[a]=="A":  num[b][0]+=1
		elif S[a]=="B":  num[b][1]+=1


def delete(x):
	if deleted[x]==1: return
	if num[x][0]==0 or num[x][1]==0:

		deleted[x]=1
		for u in nl[x]:
			if deleted[u]==0:
				if S[x]=="A": num[u][0]-=1						
				elif S[x]=="B": num[u][1]-=1
			
			if ( num[u][0]==0 or num[u][1]==0 ) and deleted[u]==0:
				delete(u)


for i in range(1,N+1):
	delete(i)


				

if sum(deleted[1:])==N:
	print "No"
else:
	print "Yes"



Fixed submission:
from heapq  import heappush, heappop

N,M=map( int, raw_input().split() )
S="z"+raw_input()
num=[ [ 0 for i in range(2) ] for j in range(N+1) ] 

nl= [ [] for j in range(N+1) ] 

deleted=[ 0 for j in range(N+1) ] 

for i in range(M):
	a,b=map( int, raw_input().split() )
	if not b in nl[a]:
		nl[a].append(b)
		nl[b].append(a)
		if S[b]=="A":  num[a][0]+=1
		elif S[b]=="B":  num[a][1]+=1
		if S[a]=="A":  num[b][0]+=1
		elif S[a]=="B":  num[b][1]+=1

hq=[]

for i in range(1,N+1):
	if num[i][0]==0 or num[i][1]==0:
		heappush(hq,i)



while hq:
	x=heappop(hq)
	if deleted[x]==1: continue
	if num[x][0]==0 or num[x][1]==0:

		deleted[x]=1
		for u in nl[x]:
			if deleted[u]==0:
				if S[x]=="A": num[u][0]-=1						
				elif S[x]=="B": num[u][1]-=1
			
		#	print "x,u,num:::",x,u,num
			if ( num[u][0]==0 or num[u][1]==0 ) and deleted[u]==0:
				heappush(hq,u)
			#	print "x,u,hq:::",x,u,hq

				

	

#print "num:::",num
#print "deleted:::",deleted
#print "nl:::",nl

if sum(deleted[1:])==N:
	print "No"
else:
	print "Yes"

Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(10**6)

N,M=map( int, raw_input().split() )
S="z"+raw_input()
num=[ [ 0 for i in range(2) ] for j in range(N+1) ] 

nl= [ [] for j in range(N+1) ] 


deleted=[ 0 for j in range(N+1) ] 

for i in range(M):
	a,b=map( int, raw_input().split() )
	if not b in nl[a]:
		nl[a].append(b)
		nl[b].append(a)
		if S[b]=="A":  num[a][0]+=1
		elif S[b]=="B":  num[a][1]+=1
		if S[a]=="A":  num[b][0]+=1
		elif S[a]=="B":  num[b][1]+=1


def delete(x):
	if deleted[x]==1: return
	if num[x][0]==0 or num[x][1]==0:

		deleted[x]=1
		for u in nl[x]:
			if deleted[u]==0:
				if S[x]=="A": num[u][0]-=1						
				elif S[x]=="B": num[u][1]-=1
			
			if ( num[u][0]==0 or num[u][1]==0 ) and deleted[u]==0:
				delete(u)


for i in range(1,N+1):
	delete(i)


				

if sum(deleted[1:])==N:
	print "No"
else:
	print "Yes"



Fixed submission:
from heapq  import heappush, heappop

N,M=map( int, raw_input().split() )
S="z"+raw_input()
num=[ [ 0 for i in range(2) ] for j in range(N+1) ] 

nl= [ [] for j in range(N+1) ] 

deleted=[ 0 for j in range(N+1) ] 

for i in range(M):
	a,b=map( int, raw_input().split() )
	if not b in nl[a]:
		nl[a].append(b)
		nl[b].append(a)
		if S[b]=="A":  num[a][0]+=1
		elif S[b]=="B":  num[a][1]+=1
		if S[a]=="A":  num[b][0]+=1
		elif S[a]=="B":  num[b][1]+=1

hq=[]

for i in range(1,N+1):
	if num[i][0]==0 or num[i][1]==0:
		heappush(hq,i)



while hq:
	x=heappop(hq)
	if deleted[x]==1: continue
	if num[x][0]==0 or num[x][1]==0:

		deleted[x]=1
		for u in nl[x]:
			if deleted[u]==0:
				if S[x]=="A": num[u][0]-=1						
				elif S[x]=="B": num[u][1]-=1
			
		#	print "x,u,num:::",x,u,num
			if ( num[u][0]==0 or num[u][1]==0 ) and deleted[u]==0:
				heappush(hq,u)
			#	print "x,u,hq:::",x,u,hq

				

	

#print "num:::",num
#print "deleted:::",deleted
#print "nl:::",nl

if sum(deleted[1:])==N:
	print "No"
else:
	print "Yes"

Buggy python submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(1000000)
N,M=map( int, raw_input().split() )
S=raw_input()

C=[ [0 for i in range(2) ] for j in range(N+1)  ] 	#C[i][0] A no kazu , C[i][1] B no kazu
nl=[ set() for i in range(N+1) ]
D=[ 0 for i in range(N+1) ]		#Mukouka flag   1:delete

for i in range(M):
	a,b=map(int, raw_input().split() )
	nl[a].add(b)
	nl[b].add(a)

	if a==b:
		if S[a-1]=="A": 
			C[a][0]+=1			
		elif S[a-1]=="B":
			C[a][1]+=1			
	else:
		if S[a-1]=="A": 
			C[b][0]+=1
		elif S[a-1]=="B":
			C[b][1]+=1
		if S[b-1]=="A": 
			C[a][0]+=1
		elif S[b-1]=="B":
			C[a][1]+=1


def func(i):
	print "i,C::",i,C,nl
	if D[i]==1: return
	a_cnt=C[i][0]
	b_cnt=C[i][1]

	if a_cnt==0 or b_cnt==0:
		D[i]=1	#Mukouka flag wo on
		for x in nl[i]:
			if D[x]==1: continue

			if a_cnt>0: C[x][0]-=1;C[i][0]-=1
			elif b_cnt>0: C[x][1]-=1;C[i][1]-=1
			if C[x][0]==0 or C[x][1]==0:
				func(x)


for i in range(1,N+1):
	func(i)



for i,x in enumerate(D):
	if i==0:continue
	if x==0:
		for u in nl[i]:
			if D[u]==0:
				print "Yes"
				quit()
else:
	print "No"



Fixed submission:
from heapq  import heappush, heappop

N,M=map( int, raw_input().split() )
S="z"+raw_input()
num=[ [ 0 for i in range(2) ] for j in range(N+1) ] 

nl= [ [] for j in range(N+1) ] 

deleted=[ 0 for j in range(N+1) ] 

for i in range(M):
	a,b=map( int, raw_input().split() )
	if not b in nl[a]:
		nl[a].append(b)
		nl[b].append(a)
		if S[b]=="A":  num[a][0]+=1
		elif S[b]=="B":  num[a][1]+=1
		if S[a]=="A":  num[b][0]+=1
		elif S[a]=="B":  num[b][1]+=1

hq=[]

for i in range(1,N+1):
	if num[i][0]==0 or num[i][1]==0:
		heappush(hq,i)



while hq:
	x=heappop(hq)
	if deleted[x]==1: continue
	if num[x][0]==0 or num[x][1]==0:

		deleted[x]=1
		for u in nl[x]:
			if deleted[u]==0:
				if S[x]=="A": num[u][0]-=1						
				elif S[x]=="B": num[u][1]-=1
			
		#	print "x,u,num:::",x,u,num
			if ( num[u][0]==0 or num[u][1]==0 ) and deleted[u]==0:
				heappush(hq,u)
			#	print "x,u,hq:::",x,u,hq

				

	

#print "num:::",num
#print "deleted:::",deleted
#print "nl:::",nl

if sum(deleted[1:])==N:
	print "No"
else:
	print "Yes"

Buggy python submission (verdict: Runtime Error):
N,M=map( int, raw_input().split() )
S=raw_input()

C=[ [0 for i in range(2) ] for j in range(N+1)  ] 
nl=[ set() for i in range(N+1) ]
D=[ 0 for i in range(N+1) ]		#Mukouka flag   1:delete

for i in range(M):
	a,b=map(int, raw_input().split() )
	nl[a].add(b)
	nl[b].add(a)

	if a==b:
		if S[a-1]=="A": 
			C[a][0]+=1			
		elif S[a-1]=="B":
			C[a][1]+=1			
	else:
		if S[a-1]=="A": 
			C[b][0]+=1
		elif S[a-1]=="B":
			C[b][1]+=1
		if S[b-1]=="A": 
			C[a][0]+=1
		elif S[b-1]=="B":
			C[a][1]+=1


def func(i):
	if D[i]==1: return
	a_cnt=C[i][0]
	b_cnt=C[i][1]

	if a_cnt==0 or b_cnt==0:
		D[i]=1	#Mukouka flag wo on
		for x in nl[i]:
			if D[x]==1: continue

			if a_cnt>0: C[x][0]-=1;C[i][0]-=1
			elif b_cnt>0: C[x][1]-=1;C[i][1]-=1
			if C[x][0]==0 or C[x][1]==0:
				func(x)


for i in range(1,N+1):
	func(i)



for i,x in enumerate(D):
	if i==0:continue
	if x==0:
		for u in nl[i]:
			if D[u]==0:
				print "Yes"
				quit()
else:
	print "No"



Fixed submission:
from heapq  import heappush, heappop

N,M=map( int, raw_input().split() )
S="z"+raw_input()
num=[ [ 0 for i in range(2) ] for j in range(N+1) ] 

nl= [ [] for j in range(N+1) ] 

deleted=[ 0 for j in range(N+1) ] 

for i in range(M):
	a,b=map( int, raw_input().split() )
	if not b in nl[a]:
		nl[a].append(b)
		nl[b].append(a)
		if S[b]=="A":  num[a][0]+=1
		elif S[b]=="B":  num[a][1]+=1
		if S[a]=="A":  num[b][0]+=1
		elif S[a]=="B":  num[b][1]+=1

hq=[]

for i in range(1,N+1):
	if num[i][0]==0 or num[i][1]==0:
		heappush(hq,i)



while hq:
	x=heappop(hq)
	if deleted[x]==1: continue
	if num[x][0]==0 or num[x][1]==0:

		deleted[x]=1
		for u in nl[x]:
			if deleted[u]==0:
				if S[x]=="A": num[u][0]-=1						
				elif S[x]=="B": num[u][1]-=1
			
		#	print "x,u,num:::",x,u,num
			if ( num[u][0]==0 or num[u][1]==0 ) and deleted[u]==0:
				heappush(hq,u)
			#	print "x,u,hq:::",x,u,hq

				

	

#print "num:::",num
#print "deleted:::",deleted
#print "nl:::",nl

if sum(deleted[1:])==N:
	print "No"
else:
	print "Yes"