Pagini recente » Cod sursa (job #71767) | Cod sursa (job #3128367) | Cod sursa (job #294971) | Cod sursa (job #3135380) | Cod sursa (job #2824832)
#include <bits/stdc++.h>
using namespace std;
class prs{
private:
FILE *fin;
char *buff;
int sp;
char read_ch(){
++sp;
if(sp==4096){
sp=0;
fread(buff,1,4096,fin);
}
return buff[sp];
}
public:
prs(const char *name){
fin=fopen(name,"r");
buff=new char [4096]();
sp-4095;
}
prs& operator >> (int &n){
char c;
while(!isdigit(c=read_ch()));
n=c-'0';
while(isdigit(c=read_ch()))
n=n*10+c-'0';
return *this;
}
};
const int nmax=int(1e5);
vector <pair<int,int>> adj[nmax];
vector <int> ans;
int elim[5*nmax+1];
int n,m;
int main()
{
prs fin("ciclueuler.in");
freopen("ciclueuler.out","w",stdout);
fin>>n>>m;
for(int i=1,x,y;i<=m;++i){
fin>>x>>y;
adj[x].push_back({y,i});
adj[y].push_back({x,i});
}
for(int i=1;i<=n;++i)
if(adj[i].size()%2==1){
cout<<"-1";
return 0;
}
stack <int> st;
st.push(1);
while(!st.empty()){
int nod=st.top();
if(adj[nod].size()){
int x=adj[nod][adj[nod].size()-1].second;
if(!elim[x]){
elim[x]=1;
st.push(adj[nod][adj[nod].size()-1].first);
}
adj[nod].pop_back();
}
else{
ans.push_back(nod);
st.pop();
}
}
for(auto x:ans)
printf("%d ",x);
}