Pagini recente » Cod sursa (job #2686997) | Cod sursa (job #2910127) | Cod sursa (job #2245442) | Cod sursa (job #1199242) | Cod sursa (job #2568884)
#include <bits/stdc++.h>
#define pb push_back
using namespace std;
class Parser {
private:
static const int SIZE = 1e5;
char str[SIZE];
int ptr;
FILE *fin;
char getChar() {
if (ptr == SIZE) {
fread(str, sizeof(char), SIZE, fin);
ptr = 0;
}
return str[ptr++];
}
int getInt() {
char chr = getChar();
while (!isdigit(chr) && chr != '-')
chr = getChar();
int sgn = +1;
if (chr == '-') {
sgn = -1;
chr = getChar();
}
int nr = 0;
while (isdigit(chr)) {
nr = nr * 10 + chr - '0';
chr = getChar();
}
return nr * sgn;
}
public:
Parser(const char* str) :
ptr(SIZE), fin(fopen(str, "r")) { }
~Parser() {
fclose(fin);
}
friend Parser& operator>>(Parser& in, int& nr) {
nr = in.getInt();
return in;
}
};
Parser fin("ciclueuler.in");
ofstream fout("ciclueuler.out");
void debug_out() { cerr << '\n'; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << " " << H; debug_out(T...);}
#define dbg(...) cerr << #__VA_ARGS__ << " ->", debug_out(__VA_ARGS__)
#define dbg_v(x, n) do{cerr<<#x"[]: ";for(int _=0;_<n;++_)cerr<<x[_]<<" ";cerr<<'\n';}while(0)
#define dbg_ok cerr<<"OK!\n"
typedef pair<int,int> pii;
typedef long long int ll;
typedef long double ld;
const int DMAX = 1e5+10;
list <pii> arb[DMAX];
vector <int> ans;
bitset <5*DMAX> id;
int n,m;
void dfs(int node);
void euler(int node);
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
int t,i,j;
int x,y;
fin>>n>>m;
for(i=1;i<=m;i++){
fin>>x>>y;
arb[x].pb({y,i});
arb[y].pb({x,i});
}
for(i=1;i<=n;i++)
if(arb[i].size() & 1){
fout<<"-1\n";
return 0;
}
euler(1);
for(i=0;i<ans.size()-1;i++)
fout<<ans[i]<<' ';
fout<<'\n';
return 0;
}
void euler(int node){
pii acm;
while(!arb[node].empty()){
acm=arb[node].back();
arb[node].pop_back();
if(id[acm.second])
continue;
id[acm.second]=true;
euler(acm.first);
}
ans.pb(node);
}