Pagini recente » Cod sursa (job #1257077) | Cod sursa (job #824798) | Cod sursa (job #1324584) | Cod sursa (job #1341709) | Cod sursa (job #2560754)
#include <bits/stdc++.h>
using namespace std;
ifstream in("ciclueuler.in");
ofstream out("ciclueuler.out");
const int Nmax = 1e5 + 5;
bool vis[Nmax];
stack <int> S;
list <int> G[Nmax];
vector<int> ans;
void dfs(int node) {
S.push(node);
while(!S.empty()) {
int x = S.top();
if(G[x].empty()) {
ans.push_back(x);
S.pop();
} else {
int y = G[x].front();
G[x].pop_front();
S.push(y);
G[y].erase(find(G[y].begin(),G[y].end(),x));
}
}
}
int main() {
ios_base::sync_with_stdio(0);
in.tie(nullptr),out.tie(0);
int N,M;
in >> N >> M;
int x,y;
while(M--) {
in >> x >> y;
G[x].push_back(y);
G[y].push_back(x);
}
for(int i = 1; i <= N; ++i)
if(G[i].size() & 1)
{
out << -1;
return 0;
}
dfs(1);
for(auto i : ans)
out << i << " ";
return 0;
}