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>
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;

#define ll long long
#define re return
#define ldb long double
#define db double
#define str string

#define fr first
#define se second
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define mkp make_pair

#define pi pair<int,int>
#define pll pair<ll,ll>
#define pdb pair<db,db>
#define pldb pair<ldb,ldb>

#define vi vector<int>
#define vll vector<ll>
#define vdb vector<db>
#define vldb vector<ldb>
#define vpi vector< pi >
#define vpll vector< pll >

#define mi map<int,int>
#define mll map<ll,ll>
#define mdb map<db,db>
#define mldb map<ldb,ldb>

#define si set<int>
#define sll set<ll>
#define sdb set<db>
#define sldb set<ldb>

#define test int t; cin>>t; while(t--)
#define scan() int n; cin>>n ; int a[n+1]; for(int i = 1 ; i<=n ; i++) cin>>a[i]
#define scan2() int n,k; cin>>n>>k ; int a[n+1]; for(int i = 1 ; i<=n ; i++) cin>>a[i]
#define print(a,n) for(int i = 0 ; i < n ; i++) cout<<a[i]<<' '
#define mem(a,v) memset(a,v,sizeof(a))

#define forr(i,a,b) for (int i = (a); i < (b); ++i)
#define rrof(i,a,b) for (int i = (b)-1; i >= (a); --i)


const int MOD = 1e9+7;
const ldb PI = 4*atan((ldb)1);

ll int get_hash(str s){
	ll int N=1000001;
	ll int base[N],A=11,MD=1110111110111;
	base[0]=1;

	forr(i,1,N)
	base[i]=(base[i-1]*A)%MD;

	ll int hs=0;
	forr(i,0,s.size()){
		hs+=(s[i]*base[i]);
		hs%=MD;
	}

	re hs;
}

ll power(ll a,ll n){
	ll res=1;

	while(n){
		if(n%2)
		res*=a;
		a*=a;
		n/=2;
	}
	
	return res;
}

int main(){
	fast;
	
	int n,m;
	cin>>n>>m;
	
	int in[n+1]={0};
	vi v[n+1];
	
	forr(i,0,m){
		int x,y;
		cin>>x>>y;
		
		in[x]++;
		in[y]++;
		
		v[x].pb(y);
		v[y].pb(x);
	}
	
	if(m%2==1){
		cout<<-1;
		re 0;
	}

	map<pi,int>mpa,mpb;
	map<pi,int>::iterator it;
	
	forr(i,1,n+1){
		int a=in[i],cnt=0;
//		cout<<a<<"\n";
		
		if(in[i]%2==1){
			forr(j,0,v[i].size()){
				if(a-cnt==1)
				break;
				
				if(mpa[{i,v[i][j]}]==0){
					mpa[{i,v[i][j]}]=1;
					mpa[{v[i][j],i}]=1;
					mpb[{i,v[i][j]}]=1;
					in[v[i][j]]--;
					cnt++;
				}
			}
		}	
		
		else{
			forr(j,0,v[i].size()){
				if(mpa[{i,v[i][j]}]==0){
					mpa[{i,v[i][j]}]=1;
					mpa[{v[i][j],i}]=1;
					mpb[{i,v[i][j]}]=1;
					in[v[i][j]]--;
				}
			}
		}
	}	
	
	for(it=mpb.begin();it!=mpb.end();++it){
		int x=(it->fr).fr;
		int y=(it->fr).se;
		
		cout<<x<<" "<<y;
		cout<<"\n";
	}
	
	re 0;
}