Pagini recente » Cod sursa (job #1785953) | Cod sursa (job #490900) | Cod sursa (job #3203076) | Cod sursa (job #572891) | Cod sursa (job #1021674)
#include<cstdio>
#include<deque>
#include<list>
#define N_MAX 100010
using namespace std;
list<int> G[N_MAX];
deque<int> Q;
inline void euler()
{
int i,y,x;
list<int> :: iterator it;
while (!Q.empty())
{
x=Q.front();
if (G[x].empty())
{
Q.pop_front();
printf("%d ",x);
}
else
{
y=G[x].back();
G[x].pop_back();
for (it=G[y].begin();it!=G[y].end();it++)
if (*it==x)
{
G[y].erase(it);
break;
}
}
}
}
inline void load()
{
int N,M,i,x,y;
bool ok=true;
scanf("%d%d",&N,&M);
for (i=1;i<=M;i++)
{
scanf("%d%d",&x,&y);
G[x].push_back(x);
G[y].push_back(y);
}
for (i=1;i<=N;i++)
Q.push_back(i);
for (i=1;i<=N;i++)
if (G[i].size()%2==1) ok=false;
if (ok) euler();
else printf("-1");
printf("\n");
}
int main()
{
freopen("ciceuler.in","r",stdin);
freopen("ciceuler.out","w",stdout);
load();
fclose(stdin);
fclose(stdout);
return 0;
}