Pagini recente » Cod sursa (job #2847928) | Cod sursa (job #2388192) | Cod sursa (job #1209896) | Statistici Trandafir Diana (trandafir_diana) | Cod sursa (job #1164409)
#include<cstdio>
#include<vector>
#include<bitset>
using namespace std;
const int nmax = 100005;
int i,n,m,x,y,g[nmax];
vector<int> v[nmax],st;
bitset<nmax> viz;
void dfs(int x)
{
for(vector<int>::iterator it=v[x].begin();it!=v[x].end();it++)
if(!viz[*it]) {viz[*it]=1; dfs(*it);}
}
int main()
{
freopen("ciclueuler.in","r",stdin);
freopen("ciclueuler.out","w",stdout);
scanf("%d%d",&n,&m);
for(;m;m--)
{
scanf("%d%d",&x,&y);
v[x].push_back(y);
v[y].push_back(x);
g[x]++; g[y]++;
}
for(i=1;i<=n;i++) if(g[i]&1) {printf("-1\n"); return 0;}
viz[1]=1; dfs(1); for(i=1;i<=n;i++) if(!viz[i]) {printf("-1\n"); return 0;}
st.push_back(1);
while(!st.empty())
{
x=st.back();
if(!v[x].empty())
{
y=v[x].back();
for(vector<int>::iterator it=v[y].begin();it!=v[y].end();it++)
if(*it==x) {*it=v[y].back(); break;}
v[x].pop_back();
v[y].pop_back();
st.push_back(y);
}
else
{
printf("%d ",st.back());
st.pop_back();
}
}
return 0;
}