Pagini recente » Cod sursa (job #1185624) | Cod sursa (job #2043056) | Cod sursa (job #2249860) | Cod sursa (job #1797523) | Cod sursa (job #1923379)
#include <iostream>
#include <fstream>
#include <vector>
#include <stack>
#define nmax 100001
#define mmax 500001
using namespace std;
int n,m;
vector<int> graf[nmax];
stack<int> st;
struct muchii
{
int x,y;
bool del=0;
}v[mmax];
void ciclu()
{
ofstream g("ciclueuler.out");
st.push(1);
while(!st.empty())
{
int topp=st.top();
if(graf[topp].size())
{
int next=graf[topp].back();
graf[topp].pop_back();
if(v[next].del)
continue;
v[next].del=1;
if(v[next].x==topp)
st.push(v[next].y);
else st.push(v[next].x);
}
else
{
g<<st.top()<<" ";
st.pop();
}
}
}
int main()
{
ifstream f("ciclueuler.in");
f>>n>>m;
for(int i=1;i<=m;i++)
{
f>>v[i].x>>v[i].y;
graf[v[i].x].push_back(i);
graf[v[i].y].push_back(i);
}
ciclu();
return 0;
}