Language: C++

#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <cstring>
#include <utility>
#include <numeric>
#include <queue>
#include <map>

using namespace std;

int main(){

    int n, m;
    cin >> n >> m;
    vector<vector<int>> E(n);
    int a, b;
    map<pair<int, int>, bool> usedEdge;
    vector<int> cnt(n, 0);
    for(int i = 0; i < m; i++){
        cin >> a >> b;
        E[a - 1].push_back(b - 1);
        E[b - 1].push_back(a - 1);
        cnt[a - 1]++;
        cnt[b - 1]++;
        usedEdge[make_pair(min(a - 1, b - 1), max(a - 1, b - 1))] = false;
    }

    queue<int> q;
    vector<bool> used(n, false);
    vector<pair<int, int>> ans;
    for(int i = 0; i < n; i++){
        if(cnt[i] == 1){
            q.push(i);
        }
    }

    vector<int> even(n, 0);
    int finish = 0;
    int index = 0;
    while(finish != n){
        if(q.empty()){
            while(used[index]){
                index++;
            }
            for(auto e: E[index]){
                int small = min(e, index);
                int big = max(e, index);
                if(!usedEdge[make_pair(small, big)]){
                    if(cnt[index] == 1){
                        used[index] = true;
                        finish++;
                        if(even[index] % 2 == 0){
                            ans.push_back(make_pair(e, index));
                            even[e]++;
                        }
                        else{
                            ans.push_back(make_pair(index, e));
                            even[index]++;
                        }
                    }
                    else{
                        ans.push_back(make_pair(index, e));
                        even[index]++;
                    }

                    usedEdge[make_pair(small, big)] = true;
                    cnt[index]--;
                    cnt[e]--;

                    if(cnt[index] == 1){
                        push(index);
                        break;
                    }

                    if(cnt[e] == 0){
                        if(even[e] % 2 != 0){
                            cout << -1 << endl;
                            return 0;
                        }
                        else{
                            finish++;
                            used[e] = true;
                        }
                    }
                    else if(cnt[e] == 1){
                        q.push(e);
                        break;
                    }
                }
            }
        }
        else{
            int temp = q.front();
            q.pop();
            if(used[temp]){
                continue;
            }
            used[temp] = true;
            finish++;
            for(auto e: E[temp]){
                int small = min(e, temp);
                int big = max(e, temp);
                if(!usedEdge[make_pair(small, big)]){
                    if(even[temp] % 2 == 0){
                        ans.push_back(make_pair(e, temp));
                        even[e]++;
                    }
                    else{
                        ans.push_back(make_pair(temp, e));
                        even[temp]++;
                    }

                    usedEdge[make_pair(small, big)] = true;
                    cnt[temp]--;
                    cnt[e]--;
                    if(cnt[e] == 0){
                        if(even[e] % 2 != 0){
                            cout << -1 << endl;
                            return 0;
                        }
                        else{
                            finish++;
                            used[e] = true;
                        }
                    }
                    else if(cnt[e] == 1){
                        q.push(e);
                    }
                }
            }
        }
    }

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

    return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:74:25: error: 'push' was not declared in this scope
   74 |                         push(index);
      |                         ^~~~