Pagini recente » Cod sursa (job #1663229) | Cod sursa (job #1880755) | Cod sursa (job #2414137) | Cod sursa (job #1487469) | Cod sursa (job #1242769)
# include <bits/stdc++.h>
using namespace std;
ifstream fi("ciclueuler.in");
ofstream fo("ciclueuler.out");
const int nmax = 1e5 + 5;
vector < int > S[nmax];
int p[nmax];
int Sol[nmax];
bool b[nmax];
void dfs(int x)
{
b[x]=1;
for (int i=0;i<p[x];++i) if (!b[S[x][i]]) dfs(S[x][i]);
}
bool eulerian(int n)
{
dfs(1);
for (int i=1;i<=n;++i) if (!b[i] || (p[i] & 1)) return 0;
return 1;
}
int main(void)
{
int n,m;
fi>>n>>m;
int x,y;
while (m--) fi>>x>>y,S[x].push_back(y),S[y].push_back(x);
for (int i=1;i<=n;++i) p[i]=int(S[i].size());
if (!eulerian(n)) return fo<<"-1\n",0;
stack < int > s;
s.push(1);
while (s.size())
{
int v=s.top();
if (!p[v]) Sol[++Sol[0]]=v,s.pop();
else
{
int to=S[v][p[v]];
s.push(to);
--p[v];S[v].pop_back();
S[to].erase(find(S[to].begin,S[to].end(),v));
p[to]=int(S[to].size());
cout << "pidar\n";
}
}
for (int i=1;i<Sol[0];++i) fo << Sol[i] << '\n';
}