Pagini recente » Cod sursa (job #2452656) | Cod sursa (job #2812666) | Cod sursa (job #1480499) | Cod sursa (job #3041367) | Cod sursa (job #2635930)
#include <bits/stdc++.h>
using namespace std;
ifstream in("ciclueuler.in");
ofstream out("ciclueuler.out");
const int lim=1e5+4;
const int lim2=5e5+4;
struct Op
{
int dest;
int ind;
};
vector<Op> vec[lim];
int tip[lim2];
bool ok[lim];
int deg[lim];
void df(int nod)
{
ok[nod]=1;
for(Op x:vec[nod])
if(!ok[x.dest])
{
tip[x.ind]=1;
df(x.dest);
}
}
bool used[lim2];
int main()
{
int n,m,x,y;
in>>n>>m;
for(int i=1;i<=m;++i)
{
in>>x>>y;
vec[x].push_back({y,i});
vec[y].push_back({x,i});
deg[x]++; deg[y]++;;
}
df(1);
for(int i=1;i<=n;++i)
{
if(deg[i]%2!=0 or ok[i]==0)
{
out<<-1<<'\n';
return 0;
}
}
int nod=1;
for(int i=1;i<=m;++i)
{
out<<nod<<' ';
bool ok=0;
for(Op x:vec[nod])
if(tip[x.ind]==0 and !used[x.ind])
{
used[x.ind]=1;
nod=x.dest;
ok=1;
break;
}
if(ok==1) continue;
for(Op x:vec[nod])
if(tip[x.ind]==1 and !used[x.ind])
{
used[x.ind]=1;
nod=x.dest;
ok=1;
break;
}
}
out<<'\n';
return 0;
}