Pagini recente » Cod sursa (job #2194466) | Cod sursa (job #345742) | Cod sursa (job #2448129) | Autentificare | Cod sursa (job #1454178)
#include <cstdio>
#include <vector>
#include <stack>
#include <algorithm>
#define nmx 100005
using namespace std;
int n, m, grad[nmx];
vector <int> g[nmx];
void euler(){
stack <int> st;
st.push(1);
while(not st.empty()){
int nod = st.top();
if(g[nod].size()){
int fiu = g[nod].back();
st.push(fiu);
g[nod].pop_back();
g[fiu].erase(find(g[fiu].begin(), g[fiu].end(), nod));
}
else{
printf("%d ", nod);
st.pop();
}
}
}
int main() {
freopen("ciclueuler.in", "r", stdin);
freopen("ciclueuler.out", "w", stdout);
scanf("%d %d", &n, &m);
for(; m; --m) {
int nod1, nod2;
scanf("%d %d", &nod1, &nod2);
g[nod1].push_back(nod2);
g[nod2].push_back(nod1);
++ grad[nod1];
++ grad[nod2];
}
for(int i = 1; i <= n; ++i)
if(grad[i] % 2) {
printf("-1\n");
return 0;
}
euler();
return 0;
}