func_code_string: #include <bits/stdc++.h>   using namespace std;   int n, m, cur;   int fa[1005];   set<int> s1, s2;   struct edge {     int from, to;     char color[2];   } e[100005];   int find(int x) { return fa[x] == x ? x : fa[x] = find(fa[x]); }   void init() {     for (int i = 1; i <= n; i++) {       fa[i] = i;     }     cur = n;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cin >> n >> m;     for (int i = 1; i <= m; i++) {       cin >> e[i].from >> e[i].to >> e[i].color;     }     if (n % 2 == 0) {       cout << -1 << endl;       return 0;     }     init();     for (int i = 1; i <= m; i++) {       if (e[i].color[0] ==  S ) {         int fx = find(e[i].from);         int fy = find(e[i].to);         if (fx != fy) {           fa[fx] = fy;           cur--;         }       }     }     if (cur - 1 > (n - 1) / 2) {       cout << -1 << endl;       return 0;     }     for (int i = 1; i <= m; i++) {       if (e[i].color[0] ==  M ) {         int fx = find(e[i].from);         int fy = find(e[i].to);         if (fx != fy) {           fa[fx] = fy;           cur--;           s2.insert(i);         }       }     }     if (cur != 1) {       cout << -1 << endl;       return 0;     }     init();     for (auto i : s2) {       int fx = find(e[i].from);       int fy = find(e[i].to);       if (fx != fy) {         fa[fx] = fy;         cur--;       }     }     for (int i = 1; i <= m; i++) {       if (s2.size() == (n - 1) / 2) break;       if (e[i].color[0] ==  M ) {         int fx = find(e[i].from);         int fy = find(e[i].to);         if (fx != fy) {           fa[fx] = fy;           cur--;           s2.insert(i);         }       }     }     if (s2.size() != (n - 1) / 2) {       cout << -1 << endl;       return 0;     }     for (int i = 1; i <= m; i++) {       if (e[i].color[0] ==  S ) {         int fx = find(e[i].from);         int fy = find(e[i].to);         if (fx != fy) {           fa[fx] = fy;           cur--;           s1.insert(i);         }       }     }     cout << n - 1 << endl;     for (auto i : s1) cout << i <<    ;     for (auto i : s2) cout << i <<    ;     cout << endl;     return 0;   }   