Language: C++

#include<algorithm>
#include<cmath>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<sstream>
#include<unordered_map>
#include<unordered_set>
#include<vector>
#include<random>
using ll = long long;
enum : int { M = (int)1e9 + 7 };
enum : ll { MLL = (ll)1e18L + 9 };
using namespace std;
#ifdef LOCAL
#include"rprint2.hpp"
#include"debug_deque.hpp"
#define vector DebugDeque
#else
#define FUNC(name) template <ostream& out = cout, class... T> void name(T&&...){ }
FUNC(prints) FUNC(printe) FUNC(printw) FUNC(printew) FUNC(printb) FUNC(printd) FUNC(printde) FUNC(printdu);
#endif
template <class S, class T>
istream& operator >> (istream& in, pair<S, T>& p){ return in >> p.first >> p.second; }
template <class T>
istream& operator >> (istream& in, vector<T>& v){ for(auto& e : v){ in >> e; } return in; }

timeval start;
double elapsed(){
    timeval now;
    gettimeofday(&now, nullptr);
    return (now.tv_sec - start.tv_sec) + (now.tv_usec - start.tv_usec) / 1e6;
}

struct Graph{
    struct Node{
        char c;
        unordered_set<int> dests;
    };
    vector<Node> nodes;
    Graph(int num): nodes(num){ }
    int id(Node* n){ return n - &nodes[0]; }
    int id(Node& n){ return &n - &nodes[0]; }
    void print(){ for(auto& node : nodes){ prints(id(node), node.dests); } }
    void addEdge(int from, int dest){
        nodes[from].dests.insert(dest);
    }
    void addEdge2(int from, int dest){
        addEdge(from, dest);
        addEdge(dest, from);
    }
    // void dfs(int idx, int from = -1){
    //     for(int didx : nodes[idx].dests){
    //         if(didx == from){ continue; }
    //         dfs(didx, idx);
    //     }
    // }
    bool bad(int idx){
        int s = 0, d = 0;
        for(int didx : nodes[idx].dests){
            s |= nodes[idx].c == nodes[didx].c;
            d |= nodes[idx].c != nodes[didx].c;
        }
        // printd(idx, s, d);
        return s + d != 2;
    }
    void erase(int idx, unordered_set<int>& cands){
        for(int didx : nodes[idx].dests){
            if(idx != didx){
                cands.insert(didx);
                nodes[didx].dests.erase(idx);
            }
        }
        nodes[idx].dests.clear();
    }
};

int main(){
    gettimeofday(&start, nullptr);
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, m;
    cin >> n >> m;
    Graph g(n);
    for(int i = 0; i < n; i++){
        char c; cin >> c;
        g.nodes[i].c = c;
    }
    for(int i = 0; i < m; i++){
        int a, b;
        cin >> a >> b;
        a--; b--;
        g.addEdge2(a, b);
    }
    g.print();

    unordered_set<int> cands;
    for(int i = 0; i < n; i++){
        cands.insert(i);
    }
    // iota(cands.begin(), cands.end(), 0);
    unordered_set<int> allBads;
    while(1){
        unordered_set<int> bads;
        for(auto i : cands){
            if(g.bad(i)){
                bads.insert(i);
            }
        }
        if(bads.empty()){ break; }
        allBads.insert(bads.begin(), bads.end());
        cands.clear();
        for(auto i : bads){
            g.erase(i, cands);
        }
        printd(bads, cands);
        if(elapsed() > 1.8){ break; }
    }
    // |v| == 1
    g.print();
    cout << ((int)allBads.size() != n ? "Yes" : "No") << '\n';
}


Compiler output:
a.cc: In function 'double elapsed()':
a.cc:34:5: error: 'gettimeofday' was not declared in this scope
   34 |     gettimeofday(&now, nullptr);
      |     ^~~~~~~~~~~~
a.cc: In function 'int main()':
a.cc:82:5: error: 'gettimeofday' was not declared in this scope
   82 |     gettimeofday(&start, nullptr);
      |     ^~~~~~~~~~~~