Language: C++

int N, M, A[101010], B[101010], L[201010], R[201010];
int bombs[101010], diff[101010];
//---------------------------------------------------------------------------------------------------
UnionFind uf2;
set<int> E[101010];
vector<int> solve(vector<int> ps, vector<int> es) {
    vector<int> res;
    fore(i, es) {
        int l = L[i];
        int r = R[i];
        if (uf2[l] == uf2[r]) continue;

        uf2(l, r);
        E[l].insert(i);
        E[r].insert(i);
    }

    queue<int> que;
    fore(p, ps) if (E[p].size() == 1) que.push(p);

    while (!que.empty()) {
        int cu = que.front(); que.pop();
        if (E[cu].size() == 0) continue;
        int i = *E[cu].begin();
        int to = (L[i] == cu) ? R[i] : L[i];

        if (diff[cu] == 1) {
            diff[cu] ^= 1;
            diff[to] ^= 1;
            res.push_back(i);
        }

        E[cu].erase(i);
        E[to].erase(i);

        if (E[to].size() == 1) que.push(to);
    }

    return res;
}
//---------------------------------------------------------------------------------------------------
void _main() {
    cin >> N >> M;
    rep(i, 0, N) cin >> A[i] >> B[i];
    rep(i, 0, M) cin >> L[i] >> R[i];

    // 座標圧縮して、[L,R]をそれに合わせて変換する
    auto dic = compress1(A, N);
    rep(i, 0, M) {
        L[i] = lower_bound(all(dic), L[i]) - dic.begin();
        R[i] = upper_bound(all(dic), R[i]) - dic.begin();
    }

    // XOR差をとる
    rep(i, 0, N) if (B[i] == 1) bombs[A[i]] = 1;
    diff[0] = bombs[0];
    rep(i, 1, N) diff[i] = bombs[i - 1] ^ bombs[i];

    // 連結成分ごとに分ける
    UnionFind uf(N + 1);
    uf2.init(N + 1);
    rep(i, 0, N) if (diff[i] == 0) uf.value[i] = 0;
    rep(i, 0, M) if(L[i] != R[i]) if(R[i] != N) uf(L[i], R[i]);

    // diffのN番目はなんでも大丈夫なので、ONの個数調整のためにメモる
    map<int, vector<int>> lasts;
    rep(i, 0, M) if (L[i] != R[i]) if (R[i] == N) lasts[uf[L[i]]].push_back(i);

    // 連結成分ごとに頂点集合を作る
    map<int, vector<int>> ps;
    rep(i, 0, N) ps[uf[i]].push_back(i);

    // 連結成分ごとに辺集合を作る
    map<int, vector<int>> es;
    rep(i, 0, M) if (L[i] != R[i]) if(uf[L[i]] == uf[R[i]]) es[uf[L[i]]].push_back(i);

    // 連結成分ごとにONの個数が偶数個か確認
    vector<int> ans;
    rep(i, 0, N) if(uf[i] == i) {
        if (uf.getValues(i) % 2 == 1) {
            if (lasts[i].size() == 0) {
                printf("-1\n");
                return;
            }
            ans.push_back(*lasts[i].begin());
            diff[L[*lasts[i].begin()]] ^= 1;
        }
        auto res = solve(ps[i], es[i]);
        fore(x, res) ans.push_back(x);
    }
    
    // 答える
    sort(all(ans));
    int n = ans.size();
    printf("%d\n", n);
    rep(i, 0, n) {
        if(i) printf(" ");
        printf("%d", ans[i] + 1);
    }
    printf("\n");
}

Compiler output:
a.cc:4:1: error: 'UnionFind' does not name a type
    4 | UnionFind uf2;
      | ^~~~~~~~~
a.cc:5:1: error: 'set' does not name a type
    5 | set<int> E[101010];
      | ^~~
a.cc:6:1: error: 'vector' does not name a type
    6 | vector<int> solve(vector<int> ps, vector<int> es) {
      | ^~~~~~
a.cc: In function 'void _main()':
a.cc:43:5: error: 'cin' was not declared in this scope
   43 |     cin >> N >> M;
      |     ^~~
a.cc:44:9: error: 'i' was not declared in this scope
   44 |     rep(i, 0, N) cin >> A[i] >> B[i];
      |         ^
a.cc:44:5: error: 'rep' was not declared in this scope
   44 |     rep(i, 0, N) cin >> A[i] >> B[i];
      |     ^~~
a.cc:48:16: error: 'compress1' was not declared in this scope
   48 |     auto dic = compress1(A, N);
      |                ^~~~~~~~~
a.cc:60:5: error: 'UnionFind' was not declared in this scope
   60 |     UnionFind uf(N + 1);
      |     ^~~~~~~~~
a.cc:61:5: error: 'uf2' was not declared in this scope
   61 |     uf2.init(N + 1);
      |     ^~~
a.cc:66:5: error: 'map' was not declared in this scope
   66 |     map<int, vector<int>> lasts;
      |     ^~~
a.cc:66:9: error: expected primary-expression before 'int'
   66 |     map<int, vector<int>> lasts;
      |         ^~~
a.cc:70:9: error: expected primary-expression before 'int'
   70 |     map<int, vector<int>> ps;
      |         ^~~
a.cc:74:9: error: expected primary-expression before 'int'
   74 |     map<int, vector<int>> es;
      |         ^~~
a.cc:78:5: error: 'vector' was not declared in this scope
   78 |     vector<int> ans;
      |     ^~~~~~
a.cc:78:12: error: expected primary-expression before 'int'
   78 |     vector<int> ans;
      |            ^~~
a.cc:93:14: error: 'ans' was not declared in this scope
   93 |     sort(all(ans));
      |              ^~~
a.cc:93:10: error: 'all' was not declared in this scope
   93 |     sort(all(ans));
      |          ^~~
a.cc:93:5: error: 'sort' was not declared in this scope; did you mean 'short'?
   93 |     sort(all(ans));
      |     ^~~~
      |     short
a.cc:95:5: error: 'printf' was not declared in this scope
   95 |     printf("%d\n", n);
      |     ^~~~~~
a.cc:1:1: note: 'printf' is defined in header '<cstdio>'; this is probably fixable by adding '#include <cstdio>'
  +++ |+#include <cstdio>
    1 | int N, M, A[101010], B[101010], L[201010], R[201010];