Pagini recente » Cod sursa (job #428844) | Cod sursa (job #624976) | Cod sursa (job #1900658) | Cod sursa (job #3037701) | Cod sursa (job #1249946)
#include <cstdio>
#include <vector>
#include <list>
using namespace std;
vector <int> g[100001];
list <int> q;
void euler (int x)
{
vector <int> :: iterator it;
q.push_front(x);
while (!q.empty())
{
x=q.front();
if (g[x].empty())
{
q.pop_front();
if (!q.empty()) printf("%d ",x);
}
else
{
int y=g[x].back();
q.push_front(y);
g[x].pop_back();
for (it=g[y].begin(); it!=g[y].end(); it++)
{
if (*it==x)
{
g[y].erase(it);
break;
}
}
}
}
}
int main()
{
int m, n, i, x, y;
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);
}
euler(1);
fclose(stdin);
fclose(stdout);
return 0;
}