Language: C++

#include <cstdio>
#include <cmath>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <random>
#include <chrono>

#ifdef _DEBUG
#define DMP(x) cerr << #x << ": " << x << "\n"
#else
#define DMP(x) ((void)0)
#endif

const int MOD = 1000000007, INF = 1111111111;
using namespace std;
using lint = long long;

#define int lint;

signed main() {

	int N, M;
	scanf("%d%d", &N, &M);

	if (M % 2 == 1) {
		printf("-1\n");
		return 0;
	}

	int u, v;
	map<pair<int, int>, int> dir;
	vector<vector<int>> edge(N);
	vector<int> out(N);
	for (int i = 0; i < M; i++) {
		scanf("%d%d", &u, &v);
		u--, v--;
		edge[u].emplace_back(v);
		edge[v].emplace_back(u);
		if (v < u) swap(u, v);
		dir[{u, v}] = 1; // intial direction is u->v when u < v
		out[u] ^= 1;
	}

	stack<pair<int,int>> que;
	vector<int> used(N);
	int idx = 2;
	que.emplace(0, 0);
	while (!que.empty()) {
		
		int now = que.top().first;
		int fliping = que.top().second;
		que.pop();
		DMP(now);
		DMP(fliping);

		idx++;
		used[now] = idx;

		if (out[now]) fliping ^= 1;

		for (const auto &e : edge[now]) {
			if (!used[e] && used[e] != used[now] - 1) {
				dir[minmax(now, e)] ^= fliping;
				out[now] ^= fliping;
				que.emplace(e, fliping);
				break;
			}
		}

		//if (all_used && fliping) {
		//	for (const auto &e : edge[now]) {
		//		if (used[e] < used[now]) {
		//			dir[minmax(now, e)] ^= fliping;
		//			out[now] ^= fliping;
		//			out[e] ^= fliping;
		//			que.emplace(e);
		//			all_used = false;
		//		}
		//	}
		//}
	}


	for (int i = 0; i < N; i++) {
		DMP(out[i]);
	}
	for (auto &e : dir) {
		if (e.second == 1) printf("%d %d\n", e.first.first + 1, e.first.second + 1);
		else printf("%d %d\n", e.first.second + 1, e.first.first + 1);
	}

	return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:24:13: error: declaration does not declare anything [-fpermissive]
   24 | #define int lint;
      |             ^~~~
a.cc:28:9: note: in expansion of macro 'int'
   28 |         int N, M;
      |         ^~~
a.cc:28:13: error: 'N' was not declared in this scope
   28 |         int N, M;
      |             ^
a.cc:28:16: error: 'M' was not declared in this scope
   28 |         int N, M;
      |                ^
a.cc:24:13: error: declaration does not declare anything [-fpermissive]
   24 | #define int lint;
      |             ^~~~
a.cc:36:9: note: in expansion of macro 'int'
   36 |         int u, v;
      |         ^~~
a.cc:36:13: error: 'u' was not declared in this scope
   36 |         int u, v;
      |             ^
a.cc:36:16: error: 'v' was not declared in this scope
   36 |         int u, v;
      |                ^
a.cc:24:13: error: wrong number of template arguments (1, should be 2)
   24 | #define int lint;
      |             ^~~~
a.cc:37:18: note: in expansion of macro 'int'
   37 |         map<pair<int, int>, int> dir;
      |                  ^~~
In file included from /usr/include/c++/14/bits/stl_algobase.h:64,
                 from /usr/include/c++/14/bits/specfun.h:43,
                 from /usr/include/c++/14/cmath:3906,
                 from a.cc:2:
/usr/include/c++/14/bits/stl_pair.h:89:12: note: provided for 'template<class _T1, class _T2> struct std::pair'
   89 |     struct pair;
      |            ^~~~
a.cc:37:13: error: wrong number of template arguments (1, should be at least 2)
   37 |         map<pair<int, int>, int> dir;
      |             ^
In file included from /usr/include/c++/14/map:63,
                 from a.cc:7:
/usr/include/c++/14/bits/stl_map.h:102:11: note: provided for 'template<class _Key, class _Tp, class _Compare, class _Alloc> class std::map'
  102 |     class map
      |           ^~~
a.cc:37:21: error: expected primary-expression before ',' token
   37 |         map<pair<int, int>, int> dir;
      |                     ^
a.cc:24:17: error: expected primary-expression before ';' token
   24 | #define int lint;
      |                 ^
a.cc:37:23: note: in expansion of macro 'int'
   37 |         map<pair<int, int>, int> dir;
      |                       ^~~
a.cc:37:26: error: expected primary-expression before '>' token
   37 |         map<pair<int, int>, int> dir;
      |                          ^
a.cc:37:27: error: expected primary-expression before ',' token
   37 |         map<pair<int, int>, int> dir;
      |                           ^
a.cc:24:17: error: expected primary-expression before ';' token
   24 | #define int lint;
      |                 ^
a.cc:37:29: note: in expansion of macro 'int'
   37 |         map<pair<int, int>, int> dir;
      |                             ^~~
a.cc:37:32: error: expected primary-expression before '>' token
   37 |         map<pair<int, int>, int> dir;
      |                                ^
a.cc:37:34: error: 'dir' was not declared in this scope; did you mean 'div'?
   37 |         map<pair<int, int>, int> dir;
      |                                  ^~~
      |                                  div
a.cc:24:13: error: template argument 1 is invalid
   24 | #define int lint;
      |             ^~~~
a.cc:38:23: note: in expansion of macro 'int'
   38 |         vector<vector<int>> edge(N);
      |                       ^~~
a.cc:24:13: error: template argument 2 is invalid
   24 | #define int lint;
      |             ^~~~
a.cc:38:23: note: in expansion of macro 'int'
   38 |         vector<vector<int>> edge(N);
      |                       ^~~
a.cc:38:16: error: template argument 1 is invalid
   38 |         vector<vector<int>> edge(N);
      |                ^
a.cc:38:16: error: template argument 2 is invalid
a.cc:38:26: error: expected primary-expression before '>>' token
   38 |         vector<vector<int>> edge(N);
      |                          ^~
a.cc:38:29: error: 'edge' was not declared in this scope
   38 |         vector<vector<int>> edge(N);
      |                             ^~~~
a.cc:24:13: error: template argument 1 is invalid
   24 | #define int lint;
      |             ^~~~
a.cc:39:16: note: in expansion of macro 'int'
   39 |         vector<int> out(N);
      |                ^~~
a.cc:24:13: error: template argument 2 is invalid
   24 | #define int lint;
      |             ^~~~
a.cc:39:16: note: in expansion of macro 'int'
   39 |         vector<int> out(N);
      |                ^~~
a.cc:39:19: error: expected primary-expression before '>' token
   39 |         vector<int> out(N);
      |                   ^
a.cc:39:21: error: 'out' was not declared in this scope
   39 |         vector<int> out(N);
      |                     ^~~
a.cc:24:13: error: declaration does not declare anything [-fpermissive]
   24 | #define int lint;
      |             ^~~~
a.cc:40:14: note: in expansion of macro 'int'
   40 |         for (int i = 0; i < M; i++) {
      |              ^~~
a.cc:40:18: error: 'i' was not declared in this scope
   40 |         for (int i = 0; i < M; i++) {
      |                  ^
a.cc:40:30: error: expected ')' before ';' token
   40 |         for (int i = 0; i < M; i++) {
      |             ~                ^
      |                              )
a.cc:40:32: error: 'i' was not declared in this scope
   40 |         for (int i = 0; i < M; i++) {
      |                                ^
a.cc:24:13: error: wrong number of template arguments (1, should be 2)
   24 | #define int lint;
      |             ^~~~
a.cc:50:20: note: in expansion of macro 'int'
   50 |         stack<pair<int,int>> que;
      |                    ^~~
/usr/include/c++/14/bits/stl_pair.h:89:12: note: provided for 'template<class _T1, class _T2> struct std::pair'
   89 |     struct pair;
      |            ^~~~
a.cc:50:15: error: template argument 1 is invalid
   50 |         stack<pair<int,int>> que;
      |               ^
a.cc:50:15: error: template argument 2 is invalid
a.cc:50:23: error: expected primary-expression before ',' token
   50 |         stack<pair<int,int>> que;
      |                       ^
a.cc:24:17: error: expected primary-expression before ';' token
   24 | #define int lint;
      |                 ^
a.cc:50:24: note: in expansion of macro 'int'
   50 |         stack<pair<int,int>> que;
      |                        ^~~
a.cc:50:27: error: expected primary-expression before '>>' token
   50 |         stack<pair<int,int>> que;
      |                           ^~
a.cc:50:30: error: 'que' was not declared in this scope
   50 |         stack<pair<int,int>> que;
      |                              ^~~
a.cc:24:13: error: template argument 1 is invalid
   24 | #define int lint;
      |             ^~~~
a.cc:51:16: note: in expansion of macro 'int'
   51 |         vector<int> used(N);
      |                ^~~
a.cc:24:13: error: template argument 2 is invalid
   24 | #define int lint;
      |             ^~~~
a.cc:51:16: note: in expansion of macro 'int'
   51 |         vector<int> used(N);
      |                ^~~
a.cc:51:19: error: expected primary-expression before '>' token
   51 |         vector<int> used(N);
      |                   ^
a.cc:51:21: error: 'used' was not declared in this scope
   51 |         vector<int> used(N);
      |                     ^~~~
a.cc:24:13: error: declaration does not declare anything [-fpermissive]
   24 | #define int lint;
      |             ^~~~
a.cc:52:9: note: in expansion of macro 'int'
   52 |         int idx = 2;
      |         ^~~
a.cc:52:13: error: 'idx' was not declared in this scope
   52 |         int idx = 2;
      |             ^~~
a.cc:24:13: error: declaration does not declare anything [-fpermissive]
   24 | #define int lint;
      |             ^~~~
a.cc:56:17: note: in expansion of macro 'int'
   56 |                 int now = que.top().first;
      |                 ^~~
a.cc:56:21: error: 'now' was not declared in this scope; did you mean 'pow'?
   56 |                 int now = que.top().first;
      |                     ^~~
      |                     pow
a.cc:24:13: error: declaration does not declare anything [-fpermissive]
   24 | #define int lint;
      |             ^~~~
a.cc:57:17: note: in expansion of macro 'int'
   57 |                 int fliping = que.top().second;
      |                 ^~~
a.cc:57:21: error: 'fliping' was not declared in this scope
   57 |                 int fliping = que.top().second;
      |                     ^~~~~~~
a.cc:24:13: error: declaration does not declare anything [-fpermissive]
   24 | #define int lint;
      |             ^~~~
a.cc:90:14: note: in expansion of macro 'int'
   90 |         for (int i = 0; i < N; i++) {
      |              ^~~
a.cc:90:30: error: expected ')' before ';' token
   90 |         for (int i = 0; i < N; i++) {
      |             ~                ^
      |                              )