Language: C++

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>
#include <cstring>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define all(c) begin(c),end(c)

template<typename T1, typename T2>
inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }

template<typename T1, typename T2>
inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }

//改造
typedef long long int ll;
using ll = long long int;
using ull = long long unsigned int;
using namespace std;
#define INF (1 << 30) - 1
#define INFl (ll)5e15
#define DEBUG 0 //デバッグする時1にしてね
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007


//ここから編集する
class Solve {
public:
    int N, M;
    vector<vector<pair<int, bool>>> G;
    vector<pair<int, int>> ans;
    vector<int> cnt;
    vector<bool> visit;

    void dfs(int v) {
        visit[v] = true;
        //辺を貼る
        for (int i = 0; i < G[v].size(); ++i) {

//        for (auto nv : G[v]) {
            auto nv = G[v][i];
            if (!nv.second) {
                if (cnt[v] % 2 == 0) {
                    //自分に向かう辺を貼る
                    ans.emplace_back(nv.first, v);
                    cnt[nv.first]++;
                } else {
                    ans.emplace_back(v, nv.first);
                    cnt[v]++;
                }
                G[v][i].second = true;
                int pt =
                        lower_bound(G[nv.first].begin(), G[nv.first].end(), make_pair(v, false)) - G[nv.first].begin();
                G[nv.first][pt].second = true;
            }
        }
        //探索する
        for (auto nv : G[v]) {
            if (!visit[nv.first]) {
                dfs(nv.first);
            }
        }
    }

    void solve() {
        cin >> N >> M;
        G.resize(N);
        cnt.resize(N);
        visit.resize(N, false);
        for (int i = 0; i < M; ++i) {
            int a, b;
            cin >> a >> b;
            a--, b--;
            G[a].push_back(make_pair(b, false));
            G[b].push_back(make_pair(a, false));
        }

        for (int i = 0; i < N; ++i) {
            sort(all(G[i]));
        }

        dfs(0);

        for (int i = 0; i < N; ++i) {
            if (cnt[i] % 2) {
                cout << -1 << endl;
                return;
            }
        }

        assert(ans.size() == M);

        for (auto e : ans) {
            cout << e.first + 1 << " " << e.second + 1 << endl;
        }

    }
};


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    Solve().solve();


    return 0;
}


Compiler output:
a.cc: In member function 'void Solve::solve()':
a.cc:122:9: error: 'assert' was not declared in this scope
  122 |         assert(ans.size() == M);
      |         ^~~~~~
a.cc:35:1: note: 'assert' is defined in header '<cassert>'; this is probably fixable by adding '#include <cassert>'
   34 | #include <cstring>
  +++ |+#include <cassert>
   35 |