Problem:
Score : 700 points

Problem Statement

You are given a simple connected undirected graph with N vertices and M edges. The vertices are numbered 1 to N, and the i-th edge connects Vertex A_i and Vertex B_i.
Takahashi will assign one of the two possible directions to each of the edges in the graph to make a directed graph.
Determine if it is possible to make a directed graph with an even number of edges going out from every vertex. If the answer is yes, construct one such graph.

Notes

An undirected graph is said to be simple when it contains no self-loops or multiple edges.

Constraints

2 \leq N \leq 10^5

N-1 \leq M \leq 10^5

1 \leq A_i,B_i \leq N (1\leq i\leq M)

The given graph is simple and connected.

Input

Input is given from Standard Input in the following format:

N M
A_1 B_1
:
A_M B_M

Output

If it is impossible to assign directions to satisfy the requirement, print -1.
Otherwise, print an assignment of directions that satisfies the requirement, in the following format:

C_1 D_1
:
C_M D_M

Here each pair (C_i, D_i) means that there is an edge directed from Vertex C_i to Vertex D_i. The edges may be printed in any order.

Sample Input 1

4 4
1 2
2 3
3 4
4 1

Sample Output 1

1 2
1 4
3 2
3 4

After this assignment of directions, Vertex 1 and 3 will each have two outgoing edges, and Vertex 2 and 4 will each have zero outgoing edges.

Sample Input 2

5 5
1 2
2 3
3 4
2 5
4 5

Sample Output 2

-1

Solution in C++14 (GCC 5.4.1) (judge verdict: Wrong Answer)

#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define ll long long int
#define vi vector<int>
#define vl vector<ll>
#define ppi pair<int,int>
#define ppl pair<ll,ll>
#define all(x) x.begin(),x.end()
#define ii int,int 
#define mm map<ii>
#define ff first    
#define ss second
#define forn(i,a,b) for(int i=a;i<b;i++)
#define forr(i,a,b) for(int i=a;i>=b;i--)
#define forv(i,m) for(auto i : m)
#define imx INT_MAX
#define imn INT_MIN
#define inf LONG_MAX
#define minf LONG_MIN
#define endl "\n"
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define sze size()
#define rvs reverse 
#define itr iterator 

/*
#define MODM(a,b,md) ((a%md)*(b%md))%md
#define MODA(a,b,md) ((a%md)+(b%md))%md
#define ull unsigned long long int
#define si short int
*/

/*
bool compare(int a,int b) {return a > b;}
bool compare1(ppi a,ppi b) {return a.ff > b.ff;}
bool compare2(ppi a,ppi b) {return a.ss < b.ss;}
ll Npower(ll a,ll b) {ll product = 1; while(b){if(b&1){product = product*a;}a = a*a;b = b>>1;} return product;}
ll power(ll a,ll b,ll md) {ll product = 1; while(b){if(b&1){product = MODM(product,a,md);}a = MODM(a,a,md);b = b>>1;} return product%md;}
ll GCD(ll a,ll b) {return b==0 ? a:GCD(b,a%b);}
ll LCM(ll a,ll b) {return (a/GCD(a,b))*b; }
*/



int main()
{
    fast

    ll n,m;

    cin>>n>>m;


        vector<pair<ll,ll>> vp;
        vector<vector<ll>> v(n);
        ll a,b;
        forn(i,0,m)
        {
            cin>>a>>b;
            vp.pb({a-1,b-1});
            v[a-1].push_back(b-1);
            v[b-1].push_back(a-1);
        }

        vector<ll> nodes(n);
        forn(i,0,n)
        {
            nodes[i] = v[i].sze;
        }

        vector<ll> v1(n,-1);

        queue<ll> q;

        q.push(0);
        vector<bool> visited(n,false); 
        visited[0] = 1;
        q.push(INT_MIN);
        ll val = 0;
        v1[0] = 1;
        while(!q.empty())
        {
            if(q.front() == INT_MIN)
            {
                val = 1-val;
                q.pop();
                if(q.empty()) break;
                q.push(INT_MIN);
            }

            ll p = q.front();
            q.pop();

            forn(i,0,v[p].size())
            {
                if(v1[v[p][i]] == (1-val))
                {
                    cout<<-1;
                    return 0;
                }
                if(!visited[v[p][i]])
                {
                    v1[v[p][i]] = val;
                    visited[v[p][i]] = true;
                    q.push(v[p][i]);
                }
            }
        }

        ll suma = 0,sumb = 0;
        bool val1 = true,val2 = true;
        forn(i,0,v1.sze)
        {
            if(v1[i] == 0)
            {
                suma += nodes[i];
                if(nodes[i]&1) val1 = false;
            }
            else
            {
                sumb += nodes[i];
                if(nodes[i]&1) val2 = false;
            }
        }

        // cout<<endl;

        if(suma%2==0 && val1)
        {
            forn(i,0,vp.size())
            {
                if(v1[vp[i].ff] == 0)
                {
                    cout<<vp[i].ff+1<<" "<<vp[i].ss+1;
                }
                else
                {
                    cout<<vp[i].ss+1<<" "<<vp[i].ff+1;
                }
                cout<<endl;
            }
        }
        else if(sumb%2==0 && val2)
        {
            forn(i,0,vp.size())
            {
                if(v1[vp[i].ff] == 1)
                {
                    cout<<vp[i].ff+1<<" "<<vp[i].ss+1;
                }
                else
                {
                    cout<<vp[i].ss+1<<" "<<vp[i].ff+1;
                }
                cout<<endl;
            }
        }
        else
        {
            cout<<-1;
            return 0;
        }


    return 0;
}