Pagini recente » Cod sursa (job #2363881) | Cod sursa (job #1742592) | Cod sursa (job #2248725) | Cod sursa (job #1710099) | Cod sursa (job #2653973)
#include<bits/stdc++.h>
#define NMAX 100005
using namespace std;
/**********************************************/
ifstream f("ciclueuler.in");
ofstream g("ciclueuler.out");
/**********************************************/
int n, m, count = 0;
int ans[NMAX];
bool vizitat[ 5 * NMAX];
vector < pair <int, int> > edges[NMAX];
vector < int > result;
/**********************************************/
///-------------------------------------------------------------
inline void readInput()
{
f >> n >> m;
for(int i = 0 ; i < m ; ++ i)
{
int a, b;
f >> a >> b;
edges[a].push_back({b, i});
edges[b].push_back({a, i});
}
}
///-------------------------------------------------------------
inline void Output(bool isntCycle)
{
if(isntCycle) g << "-1";
else
for(int i = 0 ; i < result.size() ; ++i) g<< result[i] << " ";
}
///-------------------------------------------------------------
inline void dfs(int start)
{
stack<int> st;
st.push(start);
while(!st.empty())
{
int node = st.top();
st.pop();
if(edges[node].size() == 0) result.push_back(node);
else
{
int next = edges[node].back().first;
int tip = edges[node].back().second;
edges[node].pop_back();
st.push(node);
if(!vizitat[tip])
{
vizitat[tip] = true;
st.push(next);
}
}
}
}
///-------------------------------------------------------------
inline void Solution()
{
for(int i = 1 ; i <= n ; ++i)
{
if(edges[i].size() % 2 != 0)
{
Output(true);
return;
}
}
dfs(1);
result.pop_back();
Output(false);
}
///-------------------------------------------------------------
int main()
{
readInput();
Solution();
return 0;
}