Pagini recente » Cod sursa (job #2115607) | Cod sursa (job #2059687) | Cod sursa (job #2836577) | Cod sursa (job #1725644) | Cod sursa (job #861272)
Cod sursa(job #861272)
#include <fstream>
using namespace std;
int t[100000], n, m, a[100000][100000], s[100000];
ifstream fin("ciclueuler.in");
ofstream fout("ciclueuler.out");
void DF_E(int nod)
{
fout << nod << " ";
for(int i = 1; i <= n; i++)
if(a[nod][i])
if(t[nod] != i && t[i] != nod)
{
a[nod][i] = a[i][nod] = 0;
DF_E(i);
}
for(int i = 1; i <= n; i++)
if(a[nod][i])
{
a[nod][i] = a[i][nod] = 0;
DF_E(i);
}
}
void DF(int nod)
{
s[nod] = 1;
for(int i = 1; i <= n; i++)
if(!s[i] && a[nod][i] == 1)
{
t[i] = nod;
DF(i);
}
}
int main()
{
int x, y;
fin >> n >> m;
for(int i = 1; i <= m; i++)
{
fin >> x >> y;
a[x][y] = a[y][x] =1;
}
DF(1);
DF_E(1);
fin.close();
fout.close();
return 0;
}