Pagini recente » Cod sursa (job #2255353) | Cod sursa (job #3247866) | Cod sursa (job #928751) | Cod sursa (job #2925979) | Cod sursa (job #3040848)
#include <fstream>
#include <vector>
#include <stack>
using namespace std;
ifstream fin("ciclueuler.in");
ofstream fout("ciclueuler.out");
int const N = 5e5 + 3;
int n , m;
int st[500001] , dr[500001] , viz[500001];
vector<int> v[100001];
int other(int e , int x){
return (x ^ st[e] ^ dr[e]);
}
int main(){
fin >> n >> m;
for(int i = 1 ; i <= m ; ++ i){
fin >> st[i] >> dr[i];
v[st[i]].push_back(i);
v[dr[i]].push_back(i);
}
for(int i = 1 ; i <= n ; ++ i){
if(v[i].size() & 1){
fout << "-1";
return 0;
}
}
stack<int> st;
st.push(1);
while(!st.empty()){
int x = st.top();
if(v[x].empty()){
st.pop();
if(!st.empty())
fout << x << ' ';
}else{
int e = v[x].back();
v[x].pop_back();
if(viz[e])
continue;
viz[e] = 1;
st.push(other(e , x));
}
}
return 0;
}