Pagini recente » Cod sursa (job #1828943) | Cod sursa (job #750877) | Cod sursa (job #2401829) | Cod sursa (job #1760138) | Cod sursa (job #2561372)
#include <fstream>
#include <vector>
#include <stack>
using namespace std;
const int NMAX = 1e5 + 5;
ifstream cin("ciclueulerian.in");
ofstream cout("ciclueulerian.out");
vector <pair <int, int> > g[NMAX];
int f[NMAX];
bool viz[NMAX];
stack <int> st;
vector <int> sol;
void dfs(int first, int n)
{
st.emplace(1);
while(!st.empty()) {
int node = st.top();
if(g[node].size() > 0) {
pair <int, int> curr;
curr = g[node].back();
g[node].pop_back();
if(viz[curr.second] == 0) {
viz[curr.second] = 1;
st.emplace(curr.first);
}
} else {
st.pop();
sol.emplace_back(node);
}
}
}
int main() {
int n, m;
cin >> n >> m;
for(int i = 1; i <= m; ++i) {
int x, y;
cin >> x >> y;
g[x].emplace_back(y, i);
g[y].emplace_back(x, i);
f[x]++;
f[y]++;
}
for(int i = 1; i <= n; ++i) {
if(f[i] % 2 == 1) {
cout << "-1\n";
return 0;
}
}
dfs(1, n);
sol.pop_back();
for(auto x: sol) {
cout << x << " ";
}
cout << "\n";
return 0;
}