Language: C++

#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int,int> P;

int main(){
    int n, m;
    cin >> n >> m;
    vector<vector<int> > e(100005);
    for(int i = 0; i < n; i++){
        int a, b;
        cin >> a >> b;
        e[b].push_back(a);
        e[a].push_back(b);
    }
    if(m%2)cout << -1 << endl;
    else{
        sort(e.begin(), e.end());
        priority_queue<P> one;
        vector<vector<int> > two(100005);
        for(int i = 0; i < n; i++){
            if(e[i].size()==1)one.push(P(e[i][0],i));
            else{
                for(int j = 0; j < e[i].size(); j++){
                    two[i].push_back(e[i][j]);
                    two[e[i][j]].push_back(i);
                }
            }
        }
        int pos = 0;
        while(!two[pos].size())pos++;
        while(pos < n || !one.empty()){
            while(!one.empty()){
                int f = one.top().first;
                int ff = one.top().second;
                one.pop();
                if(one.top().first == f){
                    int fff = one.top().second;
                    one.pop();
                    cout << f << ' ' << ff << endl;
                    cout << f << ' ' << fff << endl;
                }else{
                    cout << f << ' ' << ff << endl;
                    if(e[f][0] != ff){
                        cout << f << ' ' << e[f][0] << endl;
                    }
                    else{
                        cout << f << ' ' << e[f][1] <<  endl; 
                    }
                }
            }

            if(pos < n){
                cout << pos << ' ' << two[pos][0] << endl;
                cout << pos << ' ' << two[pos][1] << endl;
                two[pos].erase(0);
                two[pos].erase(0);
                if(two[pos].size() == 1){
                    one.push(P(two[pos][0], pos));
                    pos++;
                    while(pos < n && !two[pos].size())pos++;
                }
                else if(two[pos].size() == 0)pos++;
            }
        }
    }
    return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:58:31: error: no matching function for call to 'std::vector<int>::erase(int)'
   58 |                 two[pos].erase(0);
      |                 ~~~~~~~~~~~~~~^~~
In file included from /usr/include/c++/14/vector:66,
                 from /usr/include/c++/14/functional:64,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:53,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_vector.h:1536:7: note: candidate: 'std::vector<_Tp, _Alloc>::iterator std::vector<_Tp, _Alloc>::erase(const_iterator) [with _Tp = int; _Alloc = std::allocator<int>; iterator = std::vector<int>::iterator; const_iterator = std::vector<int>::const_iterator]'
 1536 |       erase(const_iterator __position)
      |       ^~~~~
/usr/include/c++/14/bits/stl_vector.h:1536:28: note:   no known conversion for argument 1 from 'int' to 'std::vector<int>::const_iterator'
 1536 |       erase(const_iterator __position)
      |             ~~~~~~~~~~~~~~~^~~~~~~~~~
/usr/include/c++/14/bits/stl_vector.h:1564:7: note: candidate: 'std::vector<_Tp, _Alloc>::iterator std::vector<_Tp, _Alloc>::erase(const_iterator, const_iterator) [with _Tp = int; _Alloc = std::allocator<int>; iterator = std::vector<int>::iterator; const_iterator = std::vector<int>::const_iterator]'
 1564 |       erase(const_iterator __first, const_iterator __last)
      |       ^~~~~
/usr/include/c++/14/bits/stl_vector.h:1564:7: note:   candidate expects 2 arguments, 1 provided
a.cc:59:31: error: no matching function for call to 'std::vector<int>::erase(int)'
   59 |                 two[pos].erase(0);
      |                 ~~~~~~~~~~~~~~^~~
/usr/include/c++/14/bits/stl_vector.h:1536:7: note: candidate: 'std::vector<_Tp, _Alloc>::iterator std::vector<_Tp, _Alloc>::erase(const_iterator) [with _Tp = int; _Alloc = std::allocator<int>; iterator = std::vector<int>::iterator; const_iterator = std::vector<int>::const_iterator]'
 1536 |       erase(const_iterator __position)
      |       ^~~~~
/usr/include/c++/14/bits/stl_vector.h:1536:28: note:   no known conversion for argument 1 from 'int' to 'std::vector<int>::const_iterator'
 1536 |       erase(const_iterator __position)
      |             ~~~~~~~~~~~~~~~^~~~~~~~~~
/usr/include/c++/14/bits/stl_vector.h:1564:7: note: candidate: 'std::vector<_Tp, _Alloc>::iterator std::vector<_Tp, _Alloc>::erase(const_iterator, const_iterator) [with _Tp = int; _Alloc = std::allocator<int>; iterator = std::vector<int>::iterator; const_iterator = std::vector<int>::const_iterator]'
 1564 |       erase(const_iterator __first, const_iterator __last)
      |       ^~~~~
/usr/include/c++/14/bits/stl_vector.h:1564:7: note:   candidate expects 2 arguments, 1 provided