Pagini recente » Cod sursa (job #2476458) | Cod sursa (job #950033) | Cod sursa (job #1201264) | Cod sursa (job #1765143) | Cod sursa (job #2087242)
#include <fstream>
#include <stack>
#include <vector>
using namespace std;
ifstream f ("ciclueuler.in");
ofstream g ("ciclueuler.out");
int n, x, y,i, ok, m, nr;
stack<int>q;
vector<int>G[100002];
void v (int u)
{
int i;
q.push(u);
while (!q.empty()){
u=q.top();
if (G[u].size()){
x=G[u][0];
q.push(x);
G[u].erase(G[u].begin()+0);
for (i=0; i<G[x].size(); i++)
if (G[x][i]==u) {
G[x].erase(G[x].begin() + i);
break;
}
}
else{
q.pop();
nr++;
if (nr<=m)
g << u << " ";
}
}
}
int main ()
{
f >> n >> m;
for (i=1; i<=m; i++){
f >> x >> y;
G[x].push_back(y);
G[y].push_back(x);
}
ok=1;
for (i=1; i<=n; i++)
if (G[i].size()%2==1){
ok=0;
break;
}
if (ok) v(1);
else g << -1;
return 0;
}