Pagini recente » Cod sursa (job #1508719) | Cod sursa (job #1350607) | Cod sursa (job #1432568) | Cod sursa (job #240188) | Cod sursa (job #752832)
Cod sursa(job #752832)
#include <cstdio>
#include <vector>
#include <list>
#include <cstring>
#define pb push_back
using namespace std;
vector<int> G[100010];
list <int> Q;
int nc, nr, i, k, N, M, x, y;
bool ok;
char s[100000];
void DF(int x)
{
int i;
vector<int>::iterator it;
Q.pb(x);
while (!Q.empty()){
x = Q.front();
if (G[x].empty()){ Q.pop_front(); printf("%d ", x); }
else {
i = G[x].back();
Q.push_front(i);
G[x].pop_back();
for(it= G[i].begin(); it!=G[i].end(); ++it)
if(*it==x) { G[i].erase(it); break;}
}
}
}
int main(){
freopen("ciclueuler.in","r", stdin);
freopen("ciclueuler.out","w",stdout);
scanf("%d %d\n", &N, &M);
for (int I=1; I<=M; ++I){
gets(s); int n = strlen(s); ok=true;
x=0; y=0;
for(i=0; i<n ; ++i)
if (s[i]==' ') ok=false;
else {
if (ok) x=x*10 + s[i]-'0'; else y = y*10+s[i]-'0';
}
// scanf("%d %d\n", &x, &y);
G[x].pb(y);
G[y].pb(x);
}
ok=true;
for(i=1; i<=N; ++i)
if (G[i].size()%2) ok=false;
if (!ok) printf("-1\n");
else DF(1);
return 0;
}