Pagini recente » Cod sursa (job #2439912) | Cod sursa (job #1869145) | Cod sursa (job #960244) | Cod sursa (job #1005614) | Cod sursa (job #1118642)
#include <fstream>
#include <iostream>
#include <vector>
#include <bitset>
#include <string.h>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <time.h>
#include <stdlib.h>
#include <set>
#include <map>
#include <string>
#include <queue>
#include <stack>
using namespace std;
const char infile[] = "ciclueuler.in";
const char outfile[] = "ciclueuler.out";
ifstream fin(infile);
ofstream fout(outfile);
const int MAXN = 100005;
const int oo = 0x3f3f3f3f;
typedef vector<int> Graph[MAXN];
typedef vector<int> :: iterator It;
const inline int min(const int &a, const int &b) { if( a > b ) return b; return a; }
const inline int max(const int &a, const int &b) { if( a < b ) return b; return a; }
const inline void Get_min(int &a, const int b) { if( a > b ) a = b; }
const inline void Get_max(int &a, const int b) { if( a < b ) a = b; }
int N, M;
Graph G;
inline void CheckEulerianProperty() {
for(int i = 1 ; i <= N ; ++ i)
if(G[i].size() & 1) {
fout << "-1\n";
exit(0);
}
}
inline void DFs(int stNode) {
stack<int> st;
st.push(stNode);
while(!st.empty()) {
int Node = st.top();
if(G[Node].size()) {
int newNode = G[Node].back();
G[Node].pop_back();
G[newNode].erase(find(G[newNode].begin(), G[newNode].end(), Node));
st.push(newNode);
}
else {
st.pop();
if(!st.empty())
fout << Node << ' ';
}
}
}
int main() {
fin >> N >> M;
for(int i = 1 ; i <= M ; ++ i) {
int x, y;
fin >> x >> y;
G[x].push_back(y);
G[y].push_back(x);
}
CheckEulerianProperty();
DFs(1);
fin.close();
fout.close();
return 0;
}