Pagini recente » Cod sursa (job #2644754) | Cod sursa (job #547480) | Cod sursa (job #1605030) | Cod sursa (job #2087884) | Cod sursa (job #2695139)
#include <bits/stdc++.h>
using namespace std;
ifstream f("ciclueuler.in");
ofstream g("ciclueuler.out");
const int N_MAX = 100001;
int N, M, grad[N_MAX];
list<int>G[N_MAX];
stack<int>S;
vector<int>sol;
void Euler()
{
S.push(1);
int x, y;
while(!S.empty())
{
x = S.top();
while(!G[x].empty())
{
y = G[x].front();
G[x].pop_front();
G[y].erase(find(G[y].begin(), G[y].end(), x));
S.push(y);
x=y;
}
sol.push_back(S.top());
S.pop();
}
}
int main()
{
f >> N >> M;
while(M--)
{
int x, y;
f >> x >> y;
G[x].push_back(y);
G[y].push_back(x);
grad[x]++;
grad[y]++;
}
for(int i = 1; i <= N; i++)
{
if(grad[i] & 1 )
{
g << "-1\n";
return 0;
}
}
Euler();
for(auto it:sol)
g<<it<<' ';
return 0;
}