Pagini recente » Cod sursa (job #1794632) | Cod sursa (job #1289616) | Cod sursa (job #2364225) | Cod sursa (job #1918110) | Cod sursa (job #2258034)
#include <bits/stdc++.h>
#define pf push_front
#define pb push_back
using namespace std;
ifstream f ("ciclueuler.in");
ofstream g ("ciclueuler.out");
const int NMax = 100005;
vector <int> G[NMax];
list <int> Q;
int n, m, x, y;
int main()
{
f >> n >> m;
for (int i = 1; i <= m; i++)
{
f >> x >> y;
G[x].pb(y);
G[y].pb(x);
}
Q.pf(1);
while (!Q.empty())
{
x = Q.front();
if (G[x].empty() == true)
{
if (Q.size() == 1) break;
g << x << " ";
Q.pop_front();
continue;
}
else
{
int aux = G[x].back();
Q.pf(aux);
G[x].pop_back();
for (int i = 0; i < G[aux].size(); i++)
{
if (G[aux][i] == x)
{
G[aux].erase(G[aux].begin() + i);
}
}
}
}
return 0;
}