func_code_string: #include <bits/stdc++.h>   using namespace std;   void bug() { cout <<     << endl; }   template <class T>   void bug(T a) {     cout << a <<     ;   }   template <class T>   void bug(T* a, int n) {     for (int i = 0; i < (n); i++) bug(a[i]);   }   int n, m;   vector<pair<pair<int, int>, bool> > e;   int ans = 1000000000;   vector<int> vs;   int fa[111111], size[111111];   int find(int u) {     if (fa[u] == u)       return u;     else       return fa[u] = find(fa[u]);   }   void merge(int u, int v) {     u = find(u);     v = find(v);     if (u == v) return;     if (size[u] > size[v]) {       size[u] += size[v];       fa[v] = u;     } else {       size[v] += size[u];       fa[u] = v;     }   }   vector<int> g[111111];   int vis[111111];   void go(bool b) {     for (int i = 0; i < (n); i++) g[i].clear();     memset(vis, -1, sizeof(vis));     for (int i = 0; i < (n); i++) {       fa[i] = i;       size[i] = 1;     }     for (int i = 0; i < (m); i++) {       int u = e[i].first.first;       int v = e[i].first.second;       bool bb = e[i].second;       if (bb == b) {         merge(u, v);       }     }     for (int i = 0; i < (m); i++) {       int u = e[i].first.first;       int v = e[i].first.second;       bool bb = e[i].second;       if (bb != b) {         u = find(u);         v = find(v);         g[u].push_back(v);         g[v].push_back(u);       }     }     int ret = 0;     vector<int> vv;     for (int i = 0; i < (n); i++)       if (find(i) == i && vis[i] == -1) {         queue<int> q;         q.push(i);         vis[i] = 0;         int zero = size[i], one = 0;         vector<int> zs, os;         zs.push_back(i);         while (q.size() > 0) {           int u = q.front();           q.pop();           for (int v : g[u]) {             if (vis[v] != -1) {               if (vis[v] != (1 - vis[u])) return;             } else {               vis[v] = (1 - vis[u]);               if (vis[v] == 0) {                 zero += size[v];                 zs.push_back(v);               } else {                 one += size[v];                 os.push_back(v);               }               q.push(v);             }           }         }         if (zero < one) {           ret += zero;           for (int i = 0; i < (zs.size()); i++) vv.push_back(zs[i]);         } else {           ret += one;           for (int i = 0; i < (os.size()); i++) vv.push_back(os[i]);         }       }     if (ans > ret) {       ans = ret;       set<int> s;       for (int i = 0; i < (vv.size()); i++) s.insert(vv[i]);       vs.clear();       for (int i = 0; i < (n); i++)         if (s.find(find(i)) != s.end()) vs.push_back(i);     }   }   int main() {     ios::sync_with_stdio(false);     cin >> n >> m;     for (int i = 0; i < (m); i++) {       int u, v;       char c;       cin >> u >> v >> c;       u--;       v--;       bool b = (c ==  B );       e.push_back(make_pair(make_pair(u, v), b));     }     go(0);     go(1);     if (ans == 1000000000)       cout << -1 << endl;     else {       cout << ans << endl;       for (int i = 0; i < (vs.size()); i++) {         cout << vs[i] + 1 <<    ;       }       cout << endl;     }     return 0;   }   