Language: C++

#pragma region Header
#ifdef DEBUG
#include "debug.hpp"
#else
#define NDEBUG
#define debug(...)
#define IFD(...)
#endif
#include <utility>
#include <cstdint>
#include <vector>
#include <tuple>
#include <algorithm>
#include <numeric>
#include <iostream>
using namespace std;
using i32 = int32_t;
using i64 = int64_t;
using u32 = uint32_t;
using u64 = uint64_t;
#define rep(i, n) for (int i = 0; i < static_cast<int>(n); ++i)
#define repd(i, n) for (int i = static_cast<int>(n) - 1; i >= 0; --i)
#define FOR(i, a, b) for (int i = static_cast<int>(a); i <= static_cast<int>(b); ++i)
#define FORD(i, b, a) for (int i = static_cast<int>(b); i >= static_cast<int>(a); --i)
template <typename T>
int SZ(T const &x)
{
    return static_cast<int>(x.size());
}
template <class T>
bool chmax(T &a, T const &b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}
template <class T>
bool chmin(T &a, T const &b)
{
    if (b < a)
    {
        a = b;
        return true;
    }
    return false;
}
#pragma endregion

struct SolveIncidenceMat
{
    using F = bool; // 体はF_2
    struct Edge
    {
        bool is_dom;
        int index, cod;
    };

    int n, m;
    vector<F> c;
    vector<vector<Edge>> adjs;

    vector<bool> used;
    vector<F> sol; // solution vector

    SolveIncidenceMat(int n, vector<pair<int, int>> const &edges, vector<F> const &c)
        : n(n), m(edges.size()), c(c), adjs(n), used(n, false), sol(m, 0)
    {
        rep(e, m)
        {
            auto [a, b] = edges[e];
            adjs[a].emplace_back(true, e, b);
            adjs[b].emplace_back(false, e, a);
        }
    }

    F dfs(int v)
    {
        used[v] = true;
        bool ret = c[v];
        for (auto &[b, e, u] : adjs[v])
        {
            if (used[u])
            {
                continue;
            }
            bool s = dfs(u);
            sol[e] = s;
            ret = ret ^ s;
        }
        return ret;
    }

    bool solve()
    {
        rep(v, n)
        {
            if (used[v])
            {
                continue;
            }
            if (dfs(v))
            {
                return false;
            }
        }

        return true;
    }
};

int main()
{
    int n, m;
    cin >> n >> m;
    vector<pair<int, int>> ab_s(n);
    rep(i, n)
    {
        cin >> ab_s[i].first >> ab_s[i].second;
        ab_s[i].first;
    }
    sort(ab_s.begin(), ab_s.end());

    vector edges(m, pair<int,int>());
    rep(i, m)
    {
        int l, r;
        cin >> l >> r;
        ++r;
        int l_ = lower_bound(ab_s.begin(), ab_s.end(), make_pair(l, -1)) - ab_s.begin();
        int r_ = lower_bound(ab_s.begin(), ab_s.end(), make_pair(r, -1)) - ab_s.begin();
        if (l_ == r_)
        { // 無駄な辺は無視
            continue;
        }
        edges[i] = {l_, r_};
    }

    // 差分
    vector dif(n + 1, false);
    transform(ab_s.begin(), ab_s.end(), dif.begin(),
              [](auto p) { return p.second == 1; });
    repd(i, n)
    {
        dif[i + 1] = dif[i + 1] ^ dif[i];
    }

    SolveIncidenceMat sim(n + 1, edges, dif);
    sim.dfs(n);
    if (not sim.solve())
    {
        cout << -1 << '\n';
        return 0;
    }

    int cnt = accumulate(sim.sol.begin(), sim.sol.end(), 0, [](int acc, bool x) {
        return acc + x;
    });
    cout << cnt << '\n';
    rep(i, m)
    {
        if (sim.sol[i])
        {
            cout << i + 1 << ' ';
        }
    }

    return 0;
}


Compiler output:
In file included from /usr/include/x86_64-linux-gnu/c++/14/bits/c++allocator.h:33,
                 from /usr/include/c++/14/bits/allocator.h:46,
                 from /usr/include/c++/14/vector:63,
                 from a.cc:11:
/usr/include/c++/14/bits/new_allocator.h: In instantiation of 'void std::__new_allocator<_Tp>::construct(_Up*, _Args&& ...) [with _Up = SolveIncidenceMat::Edge; _Args = {bool, int&, int&}; _Tp = SolveIncidenceMat::Edge]':
/usr/include/c++/14/bits/alloc_traits.h:575:17:   required from 'static void std::allocator_traits<std::allocator<_Tp1> >::construct(allocator_type&, _Up*, _Args&& ...) [with _Up = SolveIncidenceMat::Edge; _Args = {bool, int&, int&}; _Tp = SolveIncidenceMat::Edge; allocator_type = std::allocator<SolveIncidenceMat::Edge>]'
  575 |           __a.construct(__p, std::forward<_Args>(__args)...);
      |           ~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/vector.tcc:117:30:   required from 'std::vector<_Tp, _Alloc>::reference std::vector<_Tp, _Alloc>::emplace_back(_Args&& ...) [with _Args = {bool, int&, int&}; _Tp = SolveIncidenceMat::Edge; _Alloc = std::allocator<SolveIncidenceMat::Edge>; reference = SolveIncidenceMat::Edge&]'
  117 |             _Alloc_traits::construct(this->_M_impl, this->_M_impl._M_finish,
      |             ~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  118 |                                      std::forward<_Args>(__args)...);
      |                                      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:74:33:   required from here
   74 |             adjs[a].emplace_back(true, e, b);
      |             ~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~
/usr/include/c++/14/bits/new_allocator.h:191:11: error: new initializer expression list treated as compound expression [-fpermissive]
  191 |         { ::new((void *)__p) _Up(std::forward<_Args>(__args)...); }
      |           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/new_allocator.h:191:11: error: no matching function for call to 'SolveIncidenceMat::Edge::Edge(int&)'
a.cc:55:12: note: candidate: 'SolveIncidenceMat::Edge::Edge()'
   55 |     struct Edge
      |            ^~~~
a.cc:55:12: note:   candidate expects 0 arguments, 1 provided
a.cc:55:12: note: candidate: 'constexpr SolveIncidenceMat::Edge::Edge(const SolveIncidenceMat::Edge&)'
a.cc:55:12: note:   no known conversion for argument 1 from 'int' to 'const SolveIncidenceMat::Edge&'
a.cc:55:12: note: candidate: 'constexpr SolveIncidenceMat::Edge::Edge(SolveIncidenceMat::Edge&&)'
a.cc:55:12: note:   no known conversion for argument 1 from 'int' to 'SolveIncidenceMat::Edge&&'