stablegradients/pie-gem5-bysrc huggingface dataset:
// Original C++ solution (slower):
// author: Saman Mahdanian

#include <iostream>

#include <vector>

#include <queue>



using namespace std;

const int N = 2e5 + 10;



int n, m;

vector <int> g[N];

int degA[N], degB[N];

string s;

bool mark[N];

queue <int> to_do;



int32_t main() {

	cin >> n >> m >> s;

	for (int i = 0; i < m; i++) {

		int v, u;

		cin >> v >> u;

		v--; u--;

		g[v].push_back(u);

		g[u].push_back(v);

		if (s[v] == 'A')

			degA[u]++;

		else

			degB[u]++;

		if (s[u] == 'A')

			degA[v]++;

		else

			degB[v]++;

	}



	for (int v = 0; v < n; v++) {

		int all_same = true;

		for (int u: g[v])

			all_same &= s[u] == s[g[v][0]];

		if (all_same)

			to_do.push(v);

	}



	while (!to_do.empty()) {

		int v = to_do.front();

		to_do.pop();

		if (mark[v])

			continue;

		mark[v] = true;

		for (int u: g[v]) {

			if (s[v] == 'A')

				degA[u]--;

			else 

				degB[u]--;

			if (degA[u] == 0 || degB[u] == 0)

				if (!mark[u])

					to_do.push(u);

		}

	}



	for (int i = 0; i < n; i++)

		if (!mark[i]) {

			cout << "Yes" << endl;

			return 0;

		}

	cout << "No" << endl;

}

// SamMHD :: 21/11/2018 14:06:15 :: Another F****** graph...

// Optimized solution to the same problem (faster):
#include<bits/stdc++.h>

#define LL long long



using namespace std;

const int N=2e5+10;

int rd()

{

    int x=0,w=1;char ch=0;

    while(ch<'0'||ch>'9'){if(ch=='-') w=-1;ch=getchar();}

    while(ch>='0'&&ch<='9'){x=x*10+(ch^48);ch=getchar();}

    return x*w;

}

int to[N<<1],nt[N<<1],hd[N],dg[N][2],tot=1;

void adde(int x,int y)

{

    ++tot,to[tot]=y,nt[tot]=hd[x],hd[x]=tot;

    ++tot,to[tot]=x,nt[tot]=hd[y],hd[y]=tot;

}

char cc[N];

int n,m,tt;

bool v[N];



int main()

{

////////////////

    n=rd(),m=rd();

    scanf("%s",cc+1);

    for(int i=1;i<=m;++i)

    {

	int x=rd(),y=rd();

	adde(x,y);

	++dg[x][cc[y]-'A'],++dg[y][cc[x]-'A'];

    }

    queue<int> q;

    for(int i=1;i<=n;++i)

	if(!dg[i][0]||!dg[i][1]) v[i]=1,q.push(i);

    while(!q.empty())

    {

	int x=q.front();

	q.pop();

	++tt;

	for(int i=hd[x];i;i=nt[i])

	{

	    int y=to[i];

	    --dg[y][cc[x]-'A'];

	    if(!v[y]&&!dg[y][cc[x]-'A']) v[y]=1,q.push(y);

	}

    }

    puts(tt==n?"No":"Yes");

    return 0;

}






// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<bits/stdc++.h>

using namespace std;

const int maxn = 2e5 + 5;



int d1[maxn], d2[maxn];

int n, m;

string s;

bool mark[maxn];

queue <int> que;

vector<int> g[maxn];



int main() {

	ios::sync_with_stdio(false);

	cin.tie(0);

	cout.tie(0);

	

	cin >> n >> m >> s;

	for(int i = 0; i < m; i++) {

		int u, v;

		cin >> u >> v;

		u--, v--;

		if(u != v) {

			g[u].push_back(v);

			g[v].push_back(u);

			if(s[v] == 'A')

				d1[u]++;

			else

				d2[u]++;

			if(s[u] == 'A')

				d1[v]++;

			else

				d2[v]++;

		}

		else {

			g[u].push_back(u);

			if(s[v] == 'A')

				d1[u]++;

			else

				d2[u]++;

		}

	}

	

	for(int i = 0; i < n; i++) {

		if(d1[i] == 0 || d2[i] == 0) {

			que.push(i);

		}

	}

	

	while(que.size()) {

		int u = que.front();

		mark[u] = true;

//		cout << "del : " << u + 1 << endl;

		

		for(int i = 0; i < g[u].size(); i++) {

			int v = g[u][i];

			if(!mark[v]) {

				if(s[u] == 'B')

					d2[v]--;

				else

					d1[v]--;

				if((d1[v] == 0 && s[u] == 'A') || (d2[v] == 0 && s[u] == 'B')) {

					que.push(v);

				}

			}

		}

		que.pop();

	}

	

	int x = 0;

	for(int i = 0; i < n; i++) {

		if(!mark[i])

			x++;//, cout << i + 1 << " ";

	}

	

	if(x != 0)

		cout << "Yes";

	else

		cout << "No";

}

// Optimized solution to the same problem (faster):
#include<bits/stdc++.h>

#define LL long long



using namespace std;

const int N=2e5+10;

int rd()

{

    int x=0,w=1;char ch=0;

    while(ch<'0'||ch>'9'){if(ch=='-') w=-1;ch=getchar();}

    while(ch>='0'&&ch<='9'){x=x*10+(ch^48);ch=getchar();}

    return x*w;

}

int to[N<<1],nt[N<<1],hd[N],dg[N][2],tot=1;

void adde(int x,int y)

{

    ++tot,to[tot]=y,nt[tot]=hd[x],hd[x]=tot;

    ++tot,to[tot]=x,nt[tot]=hd[y],hd[y]=tot;

}

char cc[N];

int n,m,tt;

bool v[N];



int main()

{

////////////////

    n=rd(),m=rd();

    scanf("%s",cc+1);

    for(int i=1;i<=m;++i)

    {

	int x=rd(),y=rd();

	adde(x,y);

	++dg[x][cc[y]-'A'],++dg[y][cc[x]-'A'];

    }

    queue<int> q;

    for(int i=1;i<=n;++i)

	if(!dg[i][0]||!dg[i][1]) v[i]=1,q.push(i);

    while(!q.empty())

    {

	int x=q.front();

	q.pop();

	++tt;

	for(int i=hd[x];i;i=nt[i])

	{

	    int y=to[i];

	    --dg[y][cc[x]-'A'];

	    if(!v[y]&&!dg[y][cc[x]-'A']) v[y]=1,q.push(y);

	}

    }

    puts(tt==n?"No":"Yes");

    return 0;

}






// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>



using namespace std;



#define size(x) ((int) x.size())



const int MAXN = 2e5 + 5;



string s;



vector <int> adj[MAXN];



bool mark[MAXN];



int n, m;

int u, v;

int deg_a[MAXN];

int deg_b[MAXN];

int cnt;



queue <int> Q;



int main() {

	ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);

	cin >> n >> m >> s;

	for (int i = 0; i < m; i++) {

		cin >> u >> v;

		u--, v--;

		adj[u].push_back(v);

		adj[v].push_back(u);

		/*if (s[u] == 'A')

			deg_a[v]++;

		else

			deg_b[u]++;

		if (s[v] == 'A')

			deg_a[u]++;

		else

			deg_b[u]++;*/

		(s[u] == 'A' ? deg_a[v]++ : deg_b[v]++);

		(s[v] == 'A' ? deg_a[u]++ : deg_b[u]++);

	}

//	for (int i = 0; i < n; i++) 

//		cout << i << " : " << deg_a[i] << " " << deg_b[i] << endl;

	cnt = n;

	for (int i = 0; i < n; i++) 

		if (!deg_a[i] || !deg_b[i]) {

			Q.push(i);

			mark[i] = true;

		}

	while (!Q.empty()) {

		int u = Q.front();

		Q.pop();

		cnt--;

		for (int i = 0; i < size(adj[u]); i++) {

			int v = adj[u][i];

			(s[u] == 'A') ? deg_a[v]-- : deg_b[v]--;

			if ((!deg_a[v] || !deg_b[v]) && !mark[v]) {

				Q.push(v);

				mark[v] = true;

			}

		}

	}

	if (cnt)

		cout << "Yes";

	else

		cout << "No";

	cout << endl;

	return 0;

}

// Optimized solution to the same problem (faster):
#include<bits/stdc++.h>

#define LL long long



using namespace std;

const int N=2e5+10;

int rd()

{

    int x=0,w=1;char ch=0;

    while(ch<'0'||ch>'9'){if(ch=='-') w=-1;ch=getchar();}

    while(ch>='0'&&ch<='9'){x=x*10+(ch^48);ch=getchar();}

    return x*w;

}

int to[N<<1],nt[N<<1],hd[N],dg[N][2],tot=1;

void adde(int x,int y)

{

    ++tot,to[tot]=y,nt[tot]=hd[x],hd[x]=tot;

    ++tot,to[tot]=x,nt[tot]=hd[y],hd[y]=tot;

}

char cc[N];

int n,m,tt;

bool v[N];



int main()

{

////////////////

    n=rd(),m=rd();

    scanf("%s",cc+1);

    for(int i=1;i<=m;++i)

    {

	int x=rd(),y=rd();

	adde(x,y);

	++dg[x][cc[y]-'A'],++dg[y][cc[x]-'A'];

    }

    queue<int> q;

    for(int i=1;i<=n;++i)

	if(!dg[i][0]||!dg[i][1]) v[i]=1,q.push(i);

    while(!q.empty())

    {

	int x=q.front();

	q.pop();

	++tt;

	for(int i=hd[x];i;i=nt[i])

	{

	    int y=to[i];

	    --dg[y][cc[x]-'A'];

	    if(!v[y]&&!dg[y][cc[x]-'A']) v[y]=1,q.push(y);

	}

    }

    puts(tt==n?"No":"Yes");

    return 0;

}






// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>

#define int long long



using namespace std;



const int N = 2e5+10;

const string s = "AABBAABB";



vector<int> adj[N];

string label;

int reach[N][4];



void go(int u, int k) {

  if(reach[u][k] == 1) {

    cout << "Yes" << endl;

    exit(0);

  }

  if(reach[u][k] == 2) return;

  reach[u][k] = 1;

  for(int v : adj[u])

    if(s[k+1] == label[v])

      go(v, (k+1)%4);

  reach[u][k] = 2;

}



int32_t main() {

  ios::sync_with_stdio(false);

  cin.tie(0);

  int n, m;

  cin >> n >> m;



  cin >> label;



  for(int i = 0; i < m; i++) {

    int u, v;

    cin >> u >> v;

    --u, --v;

    adj[u].push_back(v);

    adj[v].push_back(u);

  }



  for(int i = 0; i < n; i++)

    if(!reach[i][0])

      go(i, 0);



  cout << "No" << endl;

}




// Optimized solution to the same problem (faster):
#include <bits/stdc++.h>

using namespace std;



typedef long long ll;

const int maxn = 200005;



inline int gi()

{

	char c = getchar();

	while (c < '0' || c > '9') c = getchar();

	int sum = 0;

	while ('0' <= c && c <= '9') sum = sum * 10 + c - 48, c = getchar();

	return sum;

}



int n, m;

char S[maxn];



struct edge

{

	int to, next;

} e[maxn * 2];

int h[maxn], deg[maxn][2], vis[maxn], tot;

int s, t, q[maxn];



void add(int u, int v)

{

	e[++tot] = (edge) {v, h[u]}; h[u] = tot;

	e[++tot] = (edge) {u, h[v]}; h[v] = tot;

	++deg[u][S[v] - 'A']; ++deg[v][S[u] - 'A'];

}



int topo()

{

	for (int i = 1; i <= n; ++i)

		if (!deg[i][0] || !deg[i][1]) q[++t] = i, vis[i] = 1;

	int cnt = 0;

	while (s < t) {

		int u = q[++s];

		++cnt;

		for (int i = h[u], v; v = e[i].to, i; i = e[i].next)

			if (!vis[v] && !(--deg[v][S[u] - 'A'])) vis[q[++t] = v] = 1;

	}

	return cnt;

}



int main()

{

	scanf("%d%d%s", &n, &m, S + 1);

	for (int i = 1; i <= m; ++i) add(gi(), gi());

	

	puts(topo() == n ? "No" : "Yes");

	

	return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>



using namespace std;

#define pb push_back

const int mn=2e5+5;



int n,m;

char s[mn];



int a[mn],b[mn];

bool vis[mn];

vector<int> g[mn];

queue<int> q;



int main() {

    scanf("%d%d",&n,&m);

    scanf("%s",s+1);

    for(int i=1; i<=m; i++) {

        int u,v;

        scanf("%d%d",&u,&v);

        g[u].pb(v);

        g[v].pb(u);

        if (s[u]=='A') a[v]++;

        else b[v]++;

        if (s[v]=='A') a[u]++;

        else b[u]++;

    }



    for(int i=1; i<=n; i++) {

        if (a[i]==0||b[i]==0) q.push(i),vis[i]=1;

    }

    while(!q.empty()) {

        int u=q.front();

        q.pop();

        for(auto &i:g[u]) {

            if (s[u]=='A') {

                a[i]--;

                if (!vis[i]&&a[i]==0) q.push(i),vis[i]=1;

            }

            else {

                b[i]--;

                if (!vis[i]&&b[i]==0) q.push(i),vis[i]=1;

            }

        }

    }

    int ans=0;

    for(int i=1; i<=n; i++)

        if (!vis[i]) ans=1;

    if (ans) puts("Yes");

    else puts("No");



    return 0;

}


// Optimized solution to the same problem (faster):
#include <bits/stdc++.h>

using namespace std;



typedef long long ll;

const int maxn = 200005;



inline int gi()

{

	char c = getchar();

	while (c < '0' || c > '9') c = getchar();

	int sum = 0;

	while ('0' <= c && c <= '9') sum = sum * 10 + c - 48, c = getchar();

	return sum;

}



int n, m;

char S[maxn];



struct edge

{

	int to, next;

} e[maxn * 2];

int h[maxn], deg[maxn][2], vis[maxn], tot;

int s, t, q[maxn];



void add(int u, int v)

{

	e[++tot] = (edge) {v, h[u]}; h[u] = tot;

	e[++tot] = (edge) {u, h[v]}; h[v] = tot;

	++deg[u][S[v] - 'A']; ++deg[v][S[u] - 'A'];

}



int topo()

{

	for (int i = 1; i <= n; ++i)

		if (!deg[i][0] || !deg[i][1]) q[++t] = i, vis[i] = 1;

	int cnt = 0;

	while (s < t) {

		int u = q[++s];

		++cnt;

		for (int i = h[u], v; v = e[i].to, i; i = e[i].next)

			if (!vis[v] && !(--deg[v][S[u] - 'A'])) vis[q[++t] = v] = 1;

	}

	return cnt;

}



int main()

{

	scanf("%d%d%s", &n, &m, S + 1);

	for (int i = 1; i <= m; ++i) add(gi(), gi());

	

	puts(topo() == n ? "No" : "Yes");

	

	return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>



using namespace std;



const int N = 2e5 + 100;



queue<int> q;

vector<int> adj[N];

bool mark[N];

char a[N];

int d1[N], d2[N];

int n, m, cnt;



int main() {

	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);

	cin >> n >> m;

	for (int i = 0; i < n; i++)

		cin >> a[i];

	for (int i = 0; i < m; i++) {

		int v, u;

		cin >> v >> u;

		adj[--v].push_back(--u);

		adj[u].push_back(v);

		(a[v] == 'A' ? d1[u]++ : d2[u]++);

		(a[u] == 'A' ? d1[v]++ : d2[v]++);

	}

	for (int i = 0; i < n; i++)

		if (!d1[i] || !d2[i]) {

			q.push(i);

			mark[i] = true;

		}

	cnt = n;

	while (!q.empty()) {

		int v = q.front();

		q.pop();

		cnt--;

		for (auto u : adj[v]) {

			(a[v] == 'A' ? d1[u]-- : d2[u]--);

			if ((!d1[u] || !d2[u]) && !mark[u]) {

				mark[u] = true;

				q.push(u);

			}

		}

	}

	return cout << (cnt ? "Yes" : "No"), 0;

}

// Optimized solution to the same problem (faster):
#include <bits/stdc++.h>

using namespace std;



typedef long long ll;

const int maxn = 200005;



inline int gi()

{

	char c = getchar();

	while (c < '0' || c > '9') c = getchar();

	int sum = 0;

	while ('0' <= c && c <= '9') sum = sum * 10 + c - 48, c = getchar();

	return sum;

}



int n, m;

char S[maxn];



struct edge

{

	int to, next;

} e[maxn * 2];

int h[maxn], deg[maxn][2], vis[maxn], tot;

int s, t, q[maxn];



void add(int u, int v)

{

	e[++tot] = (edge) {v, h[u]}; h[u] = tot;

	e[++tot] = (edge) {u, h[v]}; h[v] = tot;

	++deg[u][S[v] - 'A']; ++deg[v][S[u] - 'A'];

}



int topo()

{

	for (int i = 1; i <= n; ++i)

		if (!deg[i][0] || !deg[i][1]) q[++t] = i, vis[i] = 1;

	int cnt = 0;

	while (s < t) {

		int u = q[++s];

		++cnt;

		for (int i = h[u], v; v = e[i].to, i; i = e[i].next)

			if (!vis[v] && !(--deg[v][S[u] - 'A'])) vis[q[++t] = v] = 1;

	}

	return cnt;

}



int main()

{

	scanf("%d%d%s", &n, &m, S + 1);

	for (int i = 1; i <= m; ++i) add(gi(), gi());

	

	puts(topo() == n ? "No" : "Yes");

	

	return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<bits/stdc++.h>

#define mp make_pair

#define pb push_back

#define fi first

#define se second

#define sz(a) int(a.size())

#define clr(a) memset(a,0,sizeof(a))

#define all(a) a.begin(),a.end()

using namespace std;

typedef long long ll;

typedef unsigned long long ull;

typedef long double ld;

typedef pair<int,int> pii;

typedef pair<ll,int> pli;

const int inf=1e9;

const ll Inf=1e18;

const int N=2e5+10;

const int mod=0;

int gi() {

    int x=0,o=1;char ch=getchar();

    while((ch<'0'||ch>'9')&&ch!='-') ch=getchar();

    if(ch=='-') o=-1,ch=getchar();

    while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();

    return x*o;

}

template<typename T> bool chkmax(T &a,T b) { return a<b?a=b,1:0; };

template<typename T> bool chkmin(T &a,T b) { return a>b?a=b,1:0; };

int add(int a,int b) { return a+b>=mod?a+b-mod:a+b; }

int sub(int a,int b) { return a-b<0?a-b+mod:a-b; }

void inc(int &a,int b) { a=(a+b>=mod?a+b-mod:a+b); }

void dec(int &a,int b) { a=(a-b<0?a-b+mod:a-b); }

int n,m,a[N],b[N],vis[N];

char s[N];

vector<int> E[N];

void adde(int u,int v) {

    s[v]=='A'?++a[u]:++b[u],E[v].pb(u);

    swap(u,v);

    s[v]=='A'?++a[u]:++b[u],E[v].pb(u);

}

int main() {

    n=gi(),m=gi(),scanf("%s",s+1);

    for(int i=1,u,v;i<=m;i++) u=gi(),v=gi(),adde(u,v);

    queue<int> q;

    for(int i=1;i<=n;i++) {

        //cerr<<a[i]<<" "<<b[i]<<endl;

        if(!a[i]||!b[i]) q.push(i),vis[i]=1;

    }

    while(!q.empty()) {

        int u=q.front();q.pop();

        for(int v:E[u]) {

            s[u]=='A'?--a[v]:--b[v];

            if((!a[v]||!b[v])&&!vis[v]) vis[v]=1,q.push(v);

        }

    }

    for(int i=1;i<=n;i++) if(!vis[i]) return puts("Yes"),0;

    puts("No");

    return 0;

}


// Optimized solution to the same problem (faster):
#include <bits/stdc++.h>

using namespace std;



typedef long long ll;

const int maxn = 200005;



inline int gi()

{

	char c = getchar();

	while (c < '0' || c > '9') c = getchar();

	int sum = 0;

	while ('0' <= c && c <= '9') sum = sum * 10 + c - 48, c = getchar();

	return sum;

}



int n, m;

char S[maxn];



struct edge

{

	int to, next;

} e[maxn * 2];

int h[maxn], deg[maxn][2], vis[maxn], tot;

int s, t, q[maxn];



void add(int u, int v)

{

	e[++tot] = (edge) {v, h[u]}; h[u] = tot;

	e[++tot] = (edge) {u, h[v]}; h[v] = tot;

	++deg[u][S[v] - 'A']; ++deg[v][S[u] - 'A'];

}



int topo()

{

	for (int i = 1; i <= n; ++i)

		if (!deg[i][0] || !deg[i][1]) q[++t] = i, vis[i] = 1;

	int cnt = 0;

	while (s < t) {

		int u = q[++s];

		++cnt;

		for (int i = h[u], v; v = e[i].to, i; i = e[i].next)

			if (!vis[v] && !(--deg[v][S[u] - 'A'])) vis[q[++t] = v] = 1;

	}

	return cnt;

}



int main()

{

	scanf("%d%d%s", &n, &m, S + 1);

	for (int i = 1; i <= m; ++i) add(gi(), gi());

	

	puts(topo() == n ? "No" : "Yes");

	

	return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<bits/stdc++.h>

typedef long long ll;

ll gi(){

	ll x=0,f=1;

	char ch=getchar();

	while(!isdigit(ch))f^=ch=='-',ch=getchar();

	while(isdigit(ch))x=x*10+ch-'0',ch=getchar();

	return f?x:-x;

}

std::vector<int>G[200010];

int d[200010][2],del[200010],fa[200010];

char s[200010];

std::queue<int>que;

int hd(int x){return fa[x]==x?x:fa[x]=hd(fa[x]);}

void Union(int x,int y){

	x=hd(x),y=hd(y);

	if(x==y)puts("Yes"),exit(0);

	fa[x]=y;

}

int main(){

#ifdef XZZSB

	freopen("in.in","r",stdin);

	freopen("out.out","w",stdout);

#endif

	int n=gi(),m=gi(),a,b;

	scanf("%s",s+1);

	while(m--)a=gi(),b=gi(),G[a].push_back(b),G[b].push_back(a),++d[a][s[b]-'A'],++d[b][s[a]-'A'];

	for(int i=1;i<=n;++i)if(!d[i][0]||!d[i][1])del[i]=1,que.push(i);

	while(!que.empty()){

		int x=que.front();que.pop();

		for(int i:G[x])if(!--d[i][s[x]-'A']&&!del[i])del[i]=1,que.push(i);

	}

	for(int i=1;i<=n;++i)if(!del[i])fa[i]=i;

	for(int i=1;i<=n;++i)if(!del[i])for(int j:G[i])if(!del[j]&&j>=i)Union(i,j);

	puts("No");

	return 0;

}




// Optimized solution to the same problem (faster):
#include <bits/stdc++.h>

using namespace std;



typedef long long ll;

const int maxn = 200005;



inline int gi()

{

	char c = getchar();

	while (c < '0' || c > '9') c = getchar();

	int sum = 0;

	while ('0' <= c && c <= '9') sum = sum * 10 + c - 48, c = getchar();

	return sum;

}



int n, m;

char S[maxn];



struct edge

{

	int to, next;

} e[maxn * 2];

int h[maxn], deg[maxn][2], vis[maxn], tot;

int s, t, q[maxn];



void add(int u, int v)

{

	e[++tot] = (edge) {v, h[u]}; h[u] = tot;

	e[++tot] = (edge) {u, h[v]}; h[v] = tot;

	++deg[u][S[v] - 'A']; ++deg[v][S[u] - 'A'];

}



int topo()

{

	for (int i = 1; i <= n; ++i)

		if (!deg[i][0] || !deg[i][1]) q[++t] = i, vis[i] = 1;

	int cnt = 0;

	while (s < t) {

		int u = q[++s];

		++cnt;

		for (int i = h[u], v; v = e[i].to, i; i = e[i].next)

			if (!vis[v] && !(--deg[v][S[u] - 'A'])) vis[q[++t] = v] = 1;

	}

	return cnt;

}



int main()

{

	scanf("%d%d%s", &n, &m, S + 1);

	for (int i = 1; i <= m; ++i) add(gi(), gi());

	

	puts(topo() == n ? "No" : "Yes");

	

	return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<cstdio>

#include<queue>

using namespace std;

const int MAXN = 200000;

const int MAXM = 2000000;

struct edge{

    int to;

    edge *nxt;

}edges[MAXM + 5], *adj[4*MAXN + 5], *ecnt = &edges[0];

char s[MAXN + 5];

void addedge(int u, int v) {

    edge *p = (++ecnt);

    p->to = v, p->nxt = adj[u], adj[u] = p;

}

int indeg[4*MAXN + 5];

int main() {

    int N, M;

    scanf("%d%d", &N, &M);

    scanf("%s", s+1);

    for(int i=1;i<=M;i++) {

        int a, b;

        scanf("%d%d", &a, &b);

        if( a == b ) {

            addedge(a+N, a+2*N);

            addedge(a+3*N, a);

        }

        else {

            if( s[a] == s[b] ) {

                addedge(a+N, b);

                addedge(b+N, a);

                addedge(a+3*N, b);

                addedge(b+N, a+2*N);

                addedge(b+3*N, a);

                addedge(a+N, b+2*N);

                addedge(a+3*N, b+2*N);

                addedge(b+3*N, a+2*N);

            }

            else {

                addedge(a, b+N);

                addedge(b, a+N);

                addedge(a+2*N, b+N);

                addedge(b, a+3*N);

                addedge(b+2*N, a+N);

                addedge(a+2*N, b+N);

                addedge(a+2*N, b+3*N);

                addedge(b+2*N, a+3*N);

            }

        }

    }

    for(int i=1;i<=4*N;i++) {

        for(edge *p=adj[i];p!=NULL;p=p->nxt)

            indeg[p->to]++;

    }

    queue<int>que;

    for(int i=1;i<=4*N;i++)

        if( !indeg[i] ) que.push(i);

    int cnt = 0;

    while( !que.empty() ) {

        cnt++;

        int f = que.front(); que.pop();

        for(edge *p=adj[f];p!=NULL;p=p->nxt) {

            indeg[p->to]--;

            if( !indeg[p->to] ) que.push(p->to);

        }

    }

    if( cnt == 4*N ) puts("No");

    else puts("Yes");

}

// Optimized solution to the same problem (faster):
#include <cstdio>



const int N = 2e5 + 10;

const int M = 4e5 + 10;



int hd[N], nxt[M], to[M], cnt;

int deg[N][2];

int n, m;

char col[N];

int q[N], qhd, qtl, vis[N];



inline void adde(int x, int y) {

	cnt++;

	to[cnt] = y; nxt[cnt] = hd[x]; 

	hd[x] = cnt;

}



int main() {

	scanf("%d%d", &n, &m);

	scanf("%s", col+1);

	for (int i = 1, x, y; i <= m; ++i) {

		scanf("%d%d", &x, &y);

		adde(x, y);

		adde(y, x);

		deg[x][col[y] == 'B']++;

		deg[y][col[x] == 'B']++;

	}

	for (int i = 1; i <= n; ++i) {

		if (deg[i][0] == 0 || deg[i][1] == 0) vis[q[qtl++] = i] = 1;

	}

	while (qhd != qtl) {

		int x = q[qhd++];

		// printf("%d\n", x);

		// vis[x] = 1;

		for (int i = hd[x]; i; i = nxt[i]) if (!vis[to[i]]) {

			if (--deg[to[i]][col[x] == 'B'] == 0) {

				vis[to[i]] = 1;

				q[qtl++] = to[i];

			} 

		}

	}

	if (qtl == n) puts("No");

	else puts("Yes");

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>

using namespace std;



typedef pair<int, int> pii;

const int N = 2e5 + 100;



int n, m, u, v, d[N][2];

bool done[N];

string s;

queue<int> q;

vector<pii> nei[N];



int main() {

	ios::sync_with_stdio(false), cin.tie(0);

	cin >> n >> m >> s;

	while(m--) {

		cin >> u >> v;

		int c = (s[--u] == s[--v]);

		nei[u].push_back(pii(v, c));

		nei[v].push_back(pii(u, c));

	}

	for (int i = 0; i < n; i++)

		for (pii p: nei[i])

			d[i][p.second]++;

	for (int i = 0; i < n; i++)

		if(d[i][0] == 0 || d[i][1] == 0) {

			q.push(i);

			done[i] = true;

		}

	while(q.size()) {

		n--;

		v = q.front();

		q.pop();

		done[v] = true;

		for (pii p: nei[v]) {

			d[p.first][p.second]--;

			if(done[p.first] == false && (d[p.first][0] == 0 || d[p.first][1] == 0)) {

				done[p.first] = true;

				q.push(p.first);

			}

		}

	}

	cout << (n? "Yes": "No");

	return 0;

}

// Optimized solution to the same problem (faster):
#include<bits/stdc++.h>

#define reg register

typedef long long ll;

using namespace std;

const int MN=2e5+5;

int deg[MN][2];

int n,m;

char ch[MN];

int to[MN<<1],nxt[MN<<1],h[MN],cnt;

inline void ins(int s,int t){

	to[++cnt]=t;nxt[cnt]=h[s];h[s]=cnt;

	to[++cnt]=s;nxt[cnt]=h[t];h[t]=cnt;

}

int que[MN],ta;

int main(){

	scanf("%d%d",&n,&m);scanf("%s",ch+1);

	for(reg int i=1,s,t;i<=m;i++){

		scanf("%d%d",&s,&t);ins(s,t);

		deg[s][ch[t]-'A']++;deg[t][ch[s]-'A']++;

	}

	for(reg int i=1;i<=n;i++)

		if(!deg[i][0]||!deg[i][1])que[++ta]=i;

	for(reg int i=1;i<=ta;i++)

		for(reg int j=h[que[i]];j;j=nxt[j])

			if(deg[to[j]][0]&&deg[to[j]][1]&&!(--deg[to[j]][ch[que[i]]-'A']))

				que[++ta]=to[j];

	puts(ta<n?"Yes":"No");

	return 0;

}

// Fastest known solution for this problem: