func_code_string: #include <bits/stdc++.h>   using namespace std;   const int N_MAX = 1005, M_MAX = 100005;   struct union_find {     int rank[N_MAX], parent[N_MAX];     union_find() {       for (int i = 0; i < N_MAX; i++) {         rank[i] = 0;         parent[i] = i;       }     }     int find(int x) { return x == parent[x] ? x : parent[x] = find(parent[x]); }     bool join(int x, int y) {       x = find(x);       y = find(y);       if (x == y) return false;       if (rank[x] >= rank[y]) {         parent[y] = x;         if (rank[x] == rank[y]) rank[x]++;       } else         parent[x] = y;       return true;     }   };   struct edge {     int a, b;     char who;   };   int N, M, H;   edge edges[M_MAX];   union_find S_UF, M_UF;   int impossible() {     puts( -1 );     return 0;   }   int main() {     scanf( %d %d , &N, &M);     if (N % 2 == 0) return impossible();     H = (N - 1) / 2;     for (int i = 0; i < M; i++) {       scanf( %d %d %c , &edges[i].a, &edges[i].b, &edges[i].who);       edges[i].a--;       edges[i].b--;     }     int S = 0;     for (int i = 0; i < M; i++)       if (edges[i].who ==  S )         if (S_UF.join(edges[i].a, edges[i].b)) S++;     if (S < H) return impossible();     int components = N - S;     vector<int> answer;     for (int i = 0; i < M && (int)answer.size() < H - (components - 1); i++)       if (edges[i].who ==  M )         if (S_UF.find(edges[i].a) == S_UF.find(edges[i].b))           if (M_UF.join(edges[i].a, edges[i].b)) answer.push_back(i);     assert((int)answer.size() <= H - (components - 1));     if ((int)answer.size() != H - (components - 1)) return impossible();     for (int i = 0; i < M; i++)       if (edges[i].who ==  M )         if (S_UF.join(edges[i].a, edges[i].b)) {           assert(M_UF.join(edges[i].a, edges[i].b));           answer.push_back(i);         }     assert((int)answer.size() <= H);     if ((int)answer.size() != H) return impossible();     for (int i = 0; i < M; i++)       if (edges[i].who ==  S )         if (M_UF.join(edges[i].a, edges[i].b)) answer.push_back(i);     assert((int)answer.size() == N - 1);     printf( %d n , (int)answer.size());     for (int i = 0; i < (int)answer.size(); i++)       printf( %d%c , answer[i] + 1, i < (int)answer.size() - 1 ?     :   n );     return 0;   }   