Pagini recente » Cod sursa (job #386755) | Cod sursa (job #460176) | Cod sursa (job #2344706) | Cod sursa (job #1236690) | Cod sursa (job #2837314)
#include <iostream>
#include <fstream>
#include <vector>
#include <stack>
using namespace std;
ifstream fin ("ciclueuler.in");
ofstream fout ("ciclueuler.out");
const int MAXN = 100004, MAXM = 500004;
struct muchie
{
int x, y;
bool viz;
muchie(){viz = 0;};
muchie(int xx, int yy)
{
x = xx, y = yy, viz = 0;
}
}muchii[MAXM];
int n, m;
vector<int> nod[MAXN];
stack<int> s;
int main()
{
fin >> n >> m;
for(int i = 1; i <= m; i++)
{
int x, y;
fin >> x >> y;
muchii[i] = muchie(x, y);
nod[x].push_back(i);
nod[y].push_back(i);
}
s.push(1);
while(!s.empty())
{
int crt = s.top();
if(nod[crt].size())
{
int mh = nod[crt].back();
crt[nod].pop_back();
if(!muchii[mh].viz)
{
muchii[mh].viz = 1;
s.push(crt == muchii[mh].x ? muchii[mh].y : muchii[mh].x);
}
}
else
{
fout << crt << " ";
s.pop();
}
}
return 0;
}