Language: C++

#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <cmath>
#include <queue>

using namespace std;
typedef long long ll;
#define INF int(1e9)
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define REPONE(i, n) for(int i = 1; i <= (int)(n); i++)
#define EACH(i, mp) for(auto i:mp)
#define FOR(i, m, n) for(int i = m;i < n;i++)

const int MAX_M = 2 * (int) (1e5);
ll N, M, ab[MAX_M][MAX_M];
bool used[MAX_M][MAX_M];
string s;

bool go(int i) {
    bool has_same = false;
    bool has_diff = false;
    REP(j, N) {
        if (ab[i][j] != 1)continue;
        if (!has_same) {
            has_same = s[i] == s[j];
            if (used[i][j]) return true;
            used[i][j] = used[j][i] = true;
        }
        if (!has_diff) {
            has_diff = s[i] != s[j];
            if (used[i][j]) return true;
            used[i][j] = used[j][i] = true;
        }
        if (has_same && has_diff) {
            return go(j);
        }
    }
    return has_same && has_diff;
}

void solve() {
    REP(i, N) {
        if (go(i)) {
            cout << "Yes" << endl;
            return;
        }
    }
    cout << "No" << endl;
}

int main() {
    cin >> N >> M >> s;
    fill(used, used + N, false);
    fill(ab, ab + M, 0);
    int a, b;
    REP(i, M) {
        cin >> a >> b;
        ab[a][b] = 1;
        ab[b][a] = 1;
    }
    solve();
    return 0;
}

Compiler output:
In file included from /usr/include/c++/14/algorithm:60,
                 from a.cc:2:
/usr/include/c++/14/bits/stl_algobase.h: In instantiation of 'typename __gnu_cxx::__enable_if<std::__is_scalar<_Tp>::__value, void>::__type std::__fill_a1(_ForwardIterator, _ForwardIterator, const _Tp&) [with _ForwardIterator = bool (*)[200000]; _Tp = bool; typename __gnu_cxx::__enable_if<__is_scalar<_Tp>::__value, void>::__type = void]':
/usr/include/c++/14/bits/stl_algobase.h:998:21:   required from 'void std::__fill_a(_FIte, _FIte, const _Tp&) [with _FIte = bool (*)[200000]; _Tp = bool]'
  998 |     { std::__fill_a1(__first, __last, __value); }
      |       ~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:1029:20:   required from 'void std::fill(_ForwardIterator, _ForwardIterator, const _Tp&) [with _ForwardIterator = bool (*)[200000]; _Tp = bool]'
 1029 |       std::__fill_a(__first, __last, __value);
      |       ~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:58:9:   required from here
   58 |     fill(used, used + N, false);
      |     ~~~~^~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:952:18: error: incompatible types in assignment of 'const bool' to 'bool [200000]'
  952 |         *__first = __tmp;
      |         ~~~~~~~~~^~~~~~~
/usr/include/c++/14/bits/stl_algobase.h: In instantiation of 'typename __gnu_cxx::__enable_if<std::__is_scalar<_Tp>::__value, void>::__type std::__fill_a1(_ForwardIterator, _ForwardIterator, const _Tp&) [with _ForwardIterator = long long int (*)[200000]; _Tp = int; typename __gnu_cxx::__enable_if<__is_scalar<_Tp>::__value, void>::__type = void]':
/usr/include/c++/14/bits/stl_algobase.h:998:21:   required from 'void std::__fill_a(_FIte, _FIte, const _Tp&) [with _FIte = long long int (*)[200000]; _Tp = int]'
  998 |     { std::__fill_a1(__first, __last, __value); }
      |       ~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:1029:20:   required from 'void std::fill(_ForwardIterator, _ForwardIterator, const _Tp&) [with _ForwardIterator = long long int (*)[200000]; _Tp = int]'
 1029 |       std::__fill_a(__first, __last, __value);
      |       ~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:59:9:   required from here
   59 |     fill(ab, ab + M, 0);
      |     ~~~~^~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:952:18: error: incompatible types in assignment of 'const int' to 'long long int [200000]'
  952 |         *__first = __tmp;
      |         ~~~~~~~~~^~~~~~~