Pagini recente » Cod sursa (job #565616) | Cod sursa (job #1583117) | Cod sursa (job #2325436) | Cod sursa (job #125643) | Cod sursa (job #2215190)
#include <bits/stdc++.h>
using namespace std;
ifstream f ("ciclueuler.in");
ofstream g ("ciclueuler.out");
vector <int> :: iterator it;
vector <int> G[100002];
list <int> Q;
int n, m, x, y, nr;
int main()
{
f >> n >> m;
for (int i = 1; i <= m; i++)
{
f >> x >> y;
G[x].push_back(y);
G[y].push_back(x);
}
Q.push_back(1);
while (!Q.empty())
{
x = Q.front();
if (G[x].size() == 0)
{
if (nr < m)
{
g << x << " ";
nr++;
}
Q.pop_front();
continue;
}
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;
}
}
}
return 0;
}