Pagini recente » Cod sursa (job #2072841) | Cod sursa (job #3257197) | Cod sursa (job #2332293) | Cod sursa (job #823710) | Cod sursa (job #2238957)
#include <cstdio>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
using namespace std;
const int NMAX=100000;
const int MMAX=500000;
vector<int> g[NMAX+5];
stack<int> st;
int nod,other,n,m;
bool euler()
{
return 1;
}
void solve()
{
int i,j;
while(g[nod].size())
{
st.push(nod);
other=g[nod][g[nod].size()-1];
g[nod].pop_back();
vector<int>::iterator it;
it=find(g[other].begin(),g[other].end(),nod);
g[other].erase(it);
nod=other;
}
while(!st.empty())
{
printf("%d ", st.top());
if(!g[st.top()].empty())
{
nod=st.top();
solve();
break;
}
else
{
st.pop();
}
}
}
int main()
{
freopen("ciclueuler.in","r",stdin);
freopen("ciclueuler.out","w",stdout);
int i,j,u,v;
scanf("%d%d", &n,&m);
for(i=1;i<=m;i++)
{
scanf("%d%d", &u,&v);
g[u].push_back(v);
g[v].push_back(u);
}
nod=1;
if(euler())
solve();
else
printf("-1\n");
return 0;
}