Pagini recente » Cod sursa (job #1882356) | Monitorul de evaluare | Istoria paginii runda/tryhardereala_v2 | Cod sursa (job #773997) | Cod sursa (job #795791)
Cod sursa(job #795791)
#include<fstream>
#include<vector>
using namespace std;
vector <int> a[100001];
struct muchie
{
int x,y,z;
};
muchie v[500001];
int i,n,x,y,m;
ifstream f("ciclueuler.in");
ofstream g("ciclueuler.out");
void df(int x)
{
while (++a[x][0]<a[x].size())
{
int k=a[x][a[x][0]];
if (v[k].z==0)
{
v[k].z=1;
df(v[k].x+v[k].y-x);
}
}
g << x << ' ';
}
void df2(int x)
{
while (++a[x][0]<a[x].size())
{
int k=a[x][a[x][0]];
if (v[k].z==0)
{
v[k].z=1;
df(v[k].x+v[k].y-x);
}
}
}
int main()
{
f >> n >> m;
for (i=1;i<=n;i++)
a[i].push_back(0);
for (i=1;i<=m;i++)
{
f >> x >> y;
v[i].x=x;v[i].y=y;
a[x].push_back(i);
a[y].push_back(i);
}
for (i=1;i<=n;i++)
if (a[i].size()%2==0)
{
g << -1;
return 0;
}
df2(1);
return 0;
}