Language: C++


#include <iostream>
#include <map>
#include <set>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <fstream>
#include <bitset>
#include <queue>
#include <stack>
#include <deque>
#include <time.h>
#include <complex>

using std::cin;
using std::cout;
using std::cerr;
using std::endl;

using std::map;
using std::set;
using std::bitset;
using std::vector;
using std::string;
using std::multimap;
using std::multiset;
using std::deque;
using std::queue;
using std::stack;
using std::pair;
using std::iterator;
using std::complex;

using std::sort;
using std::stable_sort;
using std::reverse;
using std::max_element;
using std::min_element;
using std::unique;
using std::ios_base;
using std::swap;
using std::min;
using std::max;
using std::fill;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef string S;
typedef complex<double> cd;

namespace MySpace{
    struct Small_Segment_Tree{
        vector<int> a;
        int l, r;

        private:
        int __summ(int L, int R, int l, int r, int v)
        {
            if (L <= l && r <= R)
                return a[v];
            if (R <= l || r <= L)
                return 0;
            int m = (l + r) / 2;
            return __summ(L, R, l, m, 2 * v + 1) + __summ(L, R, m, r, 2 * v + 2);
        }

        void __set(int P, int l, int r, int v, int V)
        {
            if (l + 1 == r)
            {
                a[v] = V;
                return;
            }
            int m = (l + r) / 2;
            if (P < m)
            {
                __set(P, l, m, 2 * v + 1, V);
                a[v] = a[2 * v + 1] + a[2 * v + 2];
            }
            else
            {
                __set(P, m, r, 2 * v + 2, V);
                a[v] = a[2 * v + 1] + a[2 * v + 2];
            }
        }

        public:
        int Summ(int L, int R)
        {
            if (R < L)
                return 0;
            return __summ(L, R + 1, l, r, 0);
        }

        void Set(int P, int V)
        {
            __set(P, l, r, 0, V);
        }

        Small_Segment_Tree(int _n)
        {
            a.resize(4 * _n);
            l = 0, r = _n;
        }
    };
    long long inq(long long x, long long q, long long MOD)
    {
        if (q == 0)
            return 1;
        long long l = inq(x, q / 2, MOD);
        if (q % 2)
            return l * l % MOD * x % MOD;
        return l * l % MOD;
    }
};


using namespace MySpace;

#define F(i, n) for (int (i) = 0; (i) != (n); (i)++)
#define fi first
#define se second
#define re return
#define all(x) (x).begin(), (x).end()
#define int long long
const ll MOD = 998244353;

int n, m;
vector<int> graph[500000];
int curd[500000];
int vis[500000];

struct edge{
    int a, b, v, is_br;
};

vector<edge> gg;
vector<pii> ans;

void dfs(int v)
{
    if (vis[v] == 1)
        return;
    vis[v] = 1;
    for (int i = 0; i < graph[v].size(); i++)
    {
        int u = gg[graph[v][i]].a + gg[graph[v][i]].b - v;

        if (gg[graph[v][i]].v == 1)
            continue;

        if (curd[v] % 2 == 1)
        {
            ans.push_back({v, u});
            curd[v]++;
            gg[graph[v][i]].v = 1;
        }
        else
        {
            ans.push_back({u, v});
            curd[u]++;
            gg[graph[v][i]].v = 1;
        }
        dfs(u);
    }
}

int in[500000];
int out[500000];
int up[500000];
int Timer = 1;

void fs(int root, int par)
{
    if (in[root] != 0)
        return;
    in[root] = Timer++;
    up[root] = in[root];
    for (int i = 0; i < graph[root].size(); i++)
    {
        int u = gg[graph[root][i]].a + gg[graph[root][i]].b - root;
        if (u == par) continue;
        if (in[u] != 0)
        {
            up[root] = min(up[root], in[u]);
        }
        else
        {
            fs(u, root);
            up[root] = min(up[root], up[u]);
            if (up[u] > in[root])
            {
                gg[graph[root][i]].is_br = 1;
            }
        }
    }
    out[root] = Timer++;
}

int color[500000];
int flag = 1;
vector<int> bridge_tree[500000];
int dp[500000];
int res[500000];
int Bin[500000];
int Bout[500000];
int Btimer = 1;

void dfs_no_briges(int v)
{
    if (color[v] != 0)
        return;
    color[v] = flag;
    for (int i = 0; i < graph[v].size(); i++)
    {
        int u = gg[graph[v][i]].a + gg[graph[v][i]].b - v;
        if (gg[graph[v][i]].is_br == 1)
        {
            continue;
        }
        else
        {
            if (color[u] == 0)
            {
                dfs_no_briges(u);
            }
        }
    }
}

void Dfs(int v)
{
    if (Bin[v] != 0) return;
    dp[v] = res[v];
    Bin[v] = Btimer++;
    for (int i = 0; i < bridge_tree[v].size(); i++)
    {
        int u = bridge_tree[v][i];
        if (Bin[u] == 0)
        {
            Dfs(u);
            dp[v] += dp[u] + 1;
        }
    }
    Bout[v] = Btimer++;
}

signed main()
{
    ios_base::sync_with_stdio();
    cin.tie(0);
    cout.tie(0);
    cin >> n >> m;
    fill(dp, dp + n + m + 1, -1);
    if (m % 2 == 1)
    {
        cout << "-1";
        return 0;
    }
    for (int i = 0; i < m; i++)
    {
        int a, b;
        cin >> a >> b;
        graph[a].push_back(i);
        graph[b].push_back(i);
        gg.push_back({a, b, 0, 0});
    }
    fs(1, -1);

    for (int i = 1; i <= n; i++)
    {
        dfs_no_briges(i);
        flag++;
    }

    for (int i = 0; i < m; i++)
    {
        int c1 = color[gg[i].a];
        int c2 = color[gg[i].b];
        //cout << gg[i].a << " - " << c1 << " " << gg[i].b << " - " << c2 << " " << gg[i].is_br << endl;
        if (c1 == c2)
        {
            res[c1]++;
        }
        else
        {
            bridge_tree[c1].push_back(c2);
            bridge_tree[c2].push_back(c1);
        }
    }

    Dfs(1);

    for (int i = 0; i < m; i++)
    {
        if (gg[i].is_br)
        {
            int c1 = color[gg[i].a];
            int c2 = color[gg[i].b];
            //cout << c1 << " " << c2 << " " << dp[c1] << " " << dp[c2] << endl;
            if (Bin[c1] <= Bin[c2] && Bout[c2] <= Bout[c1])
            {
                int kek = dp[c2];
                if (kek % 2 == 0)
                {
                    ans.push_back({gg[i].a, gg[i].b});
                    curd[gg[i].a]++;
                    gg[i].v = 1;
                }
                else
                {
                    ans.push_back({gg[i].b, gg[i].a});
                    curd[gg[i].b]++;
                    gg[i].v = 1;
                }
            }
            else
            {
                int kek = dp[c1];
                if (kek % 2 == 0)
                {
                    ans.push_back({gg[i].b, gg[i].a});
                    curd[gg[i].b]++;
                    gg[i].v = 1;
                }
                else
                {
                    ans.push_back({gg[i].a, gg[i].b});
                    curd[gg[i].a]++;
                    gg[i].v = 1;
                }
            }
        }
    }
    for (int i = 1; i <= n; i++)
    {
        dfs(i);
    }
    for (int i = 1; i <= n; i++)
    {
        if (deg[i] % 2 != 0)
        {
            cout << "-1";
            return 0;
        }
    }
    for (int i = 0; i < ans.size(); i++)
    {
        cout << ans[i].fi << " " << ans[i].se << "\n";
    }
}


Compiler output:
a.cc: In function 'int main()':
a.cc:346:13: error: 'deg' was not declared in this scope
  346 |         if (deg[i] % 2 != 0)
      |             ^~~