Pagini recente » Cod sursa (job #2382039) | Cod sursa (job #839608) | Cod sursa (job #3029987) | Cod sursa (job #1919766) | Cod sursa (job #2315526)
#include <bits/stdc++.h>
#define x first
#define y second
using namespace std;
ifstream in("ciclueuler.in");
ofstream out("ciclueuler.out");
vector<pair<int,int>> v[100002];
int a[100002],viz[500002],k;
void dfs(int nr)
{
for(;a[nr]<v[nr].size();a[nr]++)
if(!viz[v[nr][a[nr]].y])
{
viz[v[nr][a[nr]].y]=1;
dfs(v[nr][a[nr]].x);
}
if(k--)
out<<nr<<" ";
}
int main()
{
int n,m,i,nr1,nr2;
in>>n>>m;k=m;
while(m--)
{
in>>nr1>>nr2;
v[nr1].push_back({nr2,m});
v[nr2].push_back({nr1,m});
a[nr1]++;a[nr2]++;
}
for(i=1;i<=n;i++)
{
if(a[i]%2)
{
out<<-1;
return 0;
}
a[i]=0;
}
dfs(1);
return 0;
}