Pagini recente » Cod sursa (job #2384489) | Profil M@2Te4i | Cod sursa (job #782992) | Istoria paginii utilizator/marxxim | Cod sursa (job #2172753)
#include <bits/stdc++.h>
using namespace std;
ifstream F("ciclueuler.in");
ofstream G("ciclueuler.out");
int n, m, x, y, deg[100005], z, l[100005], L;
stack<int> st;
bitset<500005> w;
vector<pair<int, int> > a[100005];
int main()
{
F >> n >> m;
for(int i = 1; i <= m; ++ i){
F>>x>>y;
a[x].push_back({y, i});
a[y].push_back({x, i});
deg[x]++;
deg[y]++;
}
for(int i = 1; i <= n; ++ i)
if(!deg[i]||deg[i]%2){
G<<-1;
return 0;
}
st.push(1);
while(!st.empty()){
x=st.top();
L=a[x].size();
while(l[x]<L){
y=a[x][l[x]].first;
z=a[x][l[x]].second;
if(!w[z]){
st.push(y);
w[z]=1;
break;
}
l[x]++;
}
if(l[x]==L){
G << x<<" ";
st.pop();
}
}
return 0;
}