Language: C++

#include<cstdio>
#include<cmath>
#include<queue>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
const int MAXN=1e5,MAXM=1e5;
int head[MAXN+5],next[MAXM+5],Cnt;
bool vis[MAXN+5],v[MAXN+5];
int cnt[MAXN+5],ind[MAXN+5],id[MAXN+5];
int n,m,root;
struct Edge
{
	int u,v;
	Edge(int _u=0,int _v=0){u=_u,v=_v;}
}E[MAXM+5];
void Addedge(int u,int v)
{
    E[++Cnt]=Edge(u,v);
    next[Cnt]=head[u];
    head[u]=Cnt;
}
void bfs(int root)
{
	int tot=0;
	queue<int> que;
	que.push(root);
	vis[root]=1;
	while(!que.empty())
	{
		int u=que.front();que.pop();
		id[u]=++tot;
		for(int i=head[u];i;i=next[i])
			if(!vis[E[i].v])
			{
				vis[E[i].v]=1;
				que.push(E[i].v);
			}
	}
}
void Solve()
{
	for(int i=n;i>=1;i--)
	{
		if(!v[i])
		{
			int u=i;
			if(ind[u]%2)
			{
				for(int i=head[u];i;i=next[i])
				{
					ind[E[i].v]++;
					v[E[i].v]=1;
					printf("%d %d\n",E[i].v,u);
				}
			}
			else
			{
				for(int i=head[u];i;i=next[i])
				{
					v[E[i].v]=1;
					printf("%d %d\n",u,E[i].v);
				}
			}
		}
	}
}
int main()
{
	//freopen("degree.in","r",stdin);
	//freopen("degree.out","w",stdout);
	scanf("%d%d",&n,&m);
	for(int i=1;i<=m;i++)
	{
		int u,v;
		scanf("%d%d",&u,&v);
		root=u;
		cnt[u]++,cnt[v]++;
		Addedge(u,v);
		Addedge(v,u); 
	}
	if(m%2)
	{
		printf("-1\n");
		return 0;
	}
	bfs(root);
	Solve();
	return 0;
}


Compiler output:
a.cc: In function 'void Addedge(int, int)':
a.cc:21:5: error: reference to 'next' is ambiguous
   21 |     next[Cnt]=head[u];
      |     ^~~~
In file included from /usr/include/c++/14/bits/stl_algobase.h:66,
                 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_iterator_base_funcs.h:232:5: note: candidates are: 'template<class _InputIterator> constexpr _InputIterator std::next(_InputIterator, typename iterator_traits<_Iter>::difference_type)'
  232 |     next(_InputIterator __x, typename
      |     ^~~~
a.cc:9:18: note:                 'int next [100005]'
    9 | int head[MAXN+5],next[MAXM+5],Cnt;
      |                  ^~~~
a.cc: In function 'void bfs(int)':
a.cc:34:39: error: reference to 'next' is ambiguous
   34 |                 for(int i=head[u];i;i=next[i])
      |                                       ^~~~
/usr/include/c++/14/bits/stl_iterator_base_funcs.h:232:5: note: candidates are: 'template<class _InputIterator> constexpr _InputIterator std::next(_InputIterator, typename iterator_traits<_Iter>::difference_type)'
  232 |     next(_InputIterator __x, typename
      |     ^~~~
a.cc:9:18: note:                 'int next [100005]'
    9 | int head[MAXN+5],next[MAXM+5],Cnt;
      |                  ^~~~
a.cc: In function 'void Solve()':
a.cc:51:55: error: reference to 'next' is ambiguous
   51 |                                 for(int i=head[u];i;i=next[i])
      |                                                       ^~~~
/usr/include/c++/14/bits/stl_iterator_base_funcs.h:232:5: note: candidates are: 'template<class _InputIterator> constexpr _InputIterator std::next(_InputIterator, typename iterator_traits<_Iter>::difference_type)'
  232 |     next(_InputIterator __x, typename
      |     ^~~~
a.cc:9:18: note:                 'int next [100005]'
    9 | int head[MAXN+5],next[MAXM+5],Cnt;
      |                  ^~~~
a.cc:60:55: error: reference to 'next' is ambiguous
   60 |                                 for(int i=head[u];i;i=next[i])
      |                                                       ^~~~
/usr/include/c++/14/bits/stl_iterator_base_funcs.h:232:5: note: candidates are: 'template<class _InputIterator> constexpr _InputIterator std::next(_InputIterator, typename iterator_traits<_Iter>::difference_type)'
  232 |     next(_InputIterator __x, typename
      |     ^~~~
a.cc:9:18: note:                 'int next [100005]'
    9 | int head[MAXN+5],next[MAXM+5],Cnt;
      |                  ^~~~