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# (Mono 4.6.2.0) (judge verdict: Wrong Answer)

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Security.Principal;
using System.Text;


struct E
{
    public int A, B;

    public E(int a, int b)
    {
        if (a > b)
        {
            int t = a;
            a = b;
            b = t;
        }

        A = a;
        B = b;
    }
}

public class Program
{
    private int N, M;
    private HashSet<int>[] EdgeAr;
    private HashSet<E> Edges;

    private int[] Cnt;

    public void Solve()
    {
        var sc = new Scanner();
        N = sc.NextInt();
        M = sc.NextInt();

        Cnt = new int[N];
        EdgeAr = new HashSet<int>[N];
        for (int i = 0; i < N; i++)
        {
            EdgeAr[i] = new HashSet<int>();
        }

        Edges = new HashSet<E>();
        for (int i = 0; i < M; i++)
        {
            int a = sc.NextInt()-1;
            int b = sc.NextInt()-1;
            Cnt[a]++;
            Cnt[b]++;
            EdgeAr[a].Add(b);
            EdgeAr[b].Add(a);
            Edges.Add(new E(a, b));
        }

        // 出てる辺が奇数本
        HashSet<int> oddNode = new HashSet<int>();

        for (int i = 0; i < N; i++)
        {
            if (Cnt[i] % 2 == 1)
            {
                oddNode.Add(i);
            }
        }

        StringBuilder sb = new StringBuilder();

        while (Edges.Count > 0)
        {
            if (oddNode.Count == 0)
            { 
                // 適当に選ぶ
                E e1 = Edges.ToArray()[0];
                int a = e1.A;
                int b = e1.B;
                // a <- b -> c
     
                Edges.Remove(e1);
                EdgeAr[a].Remove(b);
                EdgeAr[b].Remove(a);
                int c = EdgeAr[b].ToArray()[0];
                Edges.Remove(new E(b, c));
                EdgeAr[b].Remove(c);
                EdgeAr[c].Remove(b);
                oddNode.Add(a);
                oddNode.Add(c);
                sb.AppendLine($"{b + 1} {a + 1}");
                sb.AppendLine($"{b + 1} {c + 1}");
            }
            else
            {
                int a = oddNode.ToArray()[0];
                int b = EdgeAr[a].ToArray()[0];
                Edges.Remove(new E(a,b));
                EdgeAr[a].Remove(b);
                EdgeAr[b].Remove(a);
                if (EdgeAr[b].Count <= 0)
                {
                    Console.WriteLine(-1);
                    return;
                }
                // a <- b -> c
                int c = EdgeAr[b].ToArray()[0];
                oddNode.Remove(a);
                if (oddNode.Contains(c))
                {
                    oddNode.Remove(c);
                }
                else
                {
                    oddNode.Add(c);
                }
                EdgeAr[b].Remove(c);
                EdgeAr[c].Remove(b);
                Edges.Remove(new E(b, c));
                sb.AppendLine($"{b + 1} {a + 1}");
                sb.AppendLine($"{b + 1} {c + 1}");
            }
        }
        Console.Write(sb.ToString());
    }

    public static void Main(string[] args)
    {
        new Program().Solve();
    }
}

class Scanner
{
    public Scanner()
    {
        _pos = 0;
        _line = new string[0];
    }

    const char Separator = ' ';
    private int _pos;
    private string[] _line;

    #region スペース区切りで取得

    public string Next()
    {
        if (_pos >= _line.Length)
        {
            _line = Console.ReadLine().Split(Separator);
            _pos = 0;
        }

        return _line[_pos++];
    }

    public int NextInt()
    {
        return int.Parse(Next());
    }

    public long NextLong()
    {
        return long.Parse(Next());
    }

    public double NextDouble()
    {
        return double.Parse(Next());
    }

    #endregion

    #region 型変換

    private int[] ToIntArray(string[] array)
    {
        var result = new int[array.Length];
        for (int i = 0; i < array.Length; i++)
        {
            result[i] = int.Parse(array[i]);
        }

        return result;
    }

    private long[] ToLongArray(string[] array)
    {
        var result = new long[array.Length];
        for (int i = 0; i < array.Length; i++)
        {
            result[i] = long.Parse(array[i]);
        }

        return result;
    }

    private double[] ToDoubleArray(string[] array)
    {
        var result = new double[array.Length];
        for (int i = 0; i < array.Length; i++)
        {
            result[i] = double.Parse(array[i]);
        }

        return result;
    }

    #endregion

    #region 配列取得

    public string[] Array()
    {
        if (_pos >= _line.Length)
            _line = Console.ReadLine().Split(Separator);

        _pos = _line.Length;
        return _line;
    }

    public int[] IntArray()
    {
        return ToIntArray(Array());
    }

    public long[] LongArray()
    {
        return ToLongArray(Array());
    }

    public double[] DoubleArray()
    {
        return ToDoubleArray(Array());
    }

    #endregion
}