Language: C++

#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cassert>
#include <cstdint>
#include <iostream>
#include <iomanip>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <bitset>

using namespace std;

using ll =  long long;
using Pll = pair<ll, ll>;
using Pii = pair<int, int>;

constexpr ll MOD = 1000000007;
constexpr long double EPS = 1e-10;
constexpr int dyx[4][2] = {
    { 0, 1}, {-1, 0}, {0,-1}, {1, 0}
};
constexpr int V_MAX = 100000;
constexpr int E_MAX = 100000;

vector<int> outdegree(V_MAX, 0);

class UnionFind {
    public:
    int n;
    vector<int> par, rank, size;  //親, 深さ, その木の要素数

    UnionFind(int n): n(n) {
        for(int i=0;i<n;++i){
            par.push_back(i);
            rank.push_back(0);
            size.push_back(1);
        }
    }

    //根を求める
    int find(int x){
        if(par[x] == x){
            return x;
        }else{
            int p = find(par[x]);
            size[x] = size[p];
            return par[x] = p;
        }
    }

    //xとyの属する集合の併合
    void unite(int x, int y){
        x = find(x);
        y = find(y);
        if(x == y) return;
        
        size[x] += size[y];
        size[y] = size[x];
        if(rank[x] < rank[y]){
            par[x] = y;
        }else{
            par[y] = x;
            if(rank[x] == rank[y]) rank[x]++;
        }
    }

    //同じ集合に属するか否か
    bool is_same(int x, int y){
        return find(x) == find(y);
    }
};

class Edge {
    public:
    int to, rev, is_used;
    Edge(int to, int rev, int is_used): to(to), rev(rev), is_used(is_used) {}
};

vector<Edge> graph[V_MAX];

namespace kruskal {
    class Edge {
        public:
        int from, to, idx;
        Edge(int from, int to, int idx): from(from), to(to), idx(idx) {}
    };

    vector<kruskal::Edge> edges;

    ll kruskal(int V){
        ll ret = 0LL;
        UnionFind uf = UnionFind(V);
        for(Edge &e: edges){
            if(uf.is_same(e.from, e.to)){
                graph[e.from][e.idx].is_used = -1;
                graph[e.to][graph[e.from][e.idx].rev].is_used = 0;
            } else {
                uf.unite(e.from, e.to);
            }
        }
        return ret;
    }
}

void dfs(int node, int par) {
    for(Edge &child_edge: graph[node]) {
        if(child_edge.to == par) continue;
        if(child_edge.is_used != 1 && graph[child_edge.to][child_edge.rev].is_used != 1) continue;
        dfs(child_edge.to, node);
        if(outdegree[node] % 2 && outdegree[child_edge.to] % 2) {
            child_edge.is_used = 1 - child_edge.is_used;
            graph[child_edge.to][child_edge.rev].is_used = 1 - graph[child_edge.to][child_edge.rev].is_used;
            outdegree[node] = 1-outdegree[node];
            outdegree[child_edge.to] = 1-outdegree[child_edge.to];
        }
    }
    for(Edge child_edge: graph[node]) {
        assert(degree[child_edge.to]%2 == 0);
    }
}

int main() {
    std::ios::sync_with_stdio(0); cin.tie(0);
    int n,m,a,b;
    cin >> n >> m;

    for(int i=0;i<m;++i){
        cin >> a >> b;
        --a; --b;
        graph[a].push_back(Edge(b, graph[b].size(), 1));
        graph[b].push_back(Edge(a, graph[a].size()-1, 0));
        kruskal::edges.push_back(kruskal::Edge(a, b, graph[a].size()-1));
        outdegree[a] = 1-outdegree[a];
    }
    if(m % 2) {
        cout << -1 << endl;
        return 0;
    }

    kruskal::kruskal(n);
    
    dfs(0, -1);

    for(int i=0;i<n;++i) {
        for(Edge e: graph[i]) {
            if(e.is_used) cout << i+1 << " " << e.to+1 << endl;
        }
    }
}


Compiler output:
In file included from /usr/include/c++/14/cassert:44,
                 from a.cc:5:
a.cc: In function 'void dfs(int, int)':
a.cc:126:16: error: 'degree' was not declared in this scope; did you mean 'outdegree'?
  126 |         assert(degree[child_edge.to]%2 == 0);
      |                ^~~~~~