Pagini recente » Cod sursa (job #1941168) | Cod sursa (job #2710936) | Cod sursa (job #919546) | Cod sursa (job #1001691) | Cod sursa (job #2371336)
#include <cstdio>
#include <list>
#include <vector>
#define N 100050
using namespace std;
vector <int> g[N];
list <int> q;
int n,m,i,x,y,nr;
bool ok;
void euler(int x) {
q.push_back(x);
vector <int>::iterator it;
while ( !q.empty() )
{
x=q.front ();
if(g[x].empty())
{
q.pop_front();
if (!q.empty()) printf("%d ", x);
}
else
{
int nod=g[x].back();
q.push_front(nod);
g[x].pop_back();
for ( it = g[nod].begin(); it!=g[nod].end(); it++)
if (*it==x) {
g[nod].erase(it);
break;
}
}
}
}
int main() {
freopen ("ciclueuler.in", "r",stdin );
freopen ("ciclueuler.out", "w", stdout);
scanf ("%d%d", &n,&m);
for (i=1; i<=m; i++) {
scanf ("%d%d", &x, &y);
g[x].push_back(y);
g[y].push_back(x);
}
for (i=1;i<=n;i++)
{
if (g[i].size()%2)
ok=false; break;
}
if (!ok)
printf ("-1\n");
else
euler (1);
return 0;
}