Pagini recente » Cod sursa (job #2277357) | Cod sursa (job #1103076) | Cod sursa (job #1066910) | Cod sursa (job #1153398) | Cod sursa (job #1604536)
#include <fstream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#define inf 1<<30
#define x first
#define y second
using namespace std;
ifstream fin("ciclueuler.in");
ofstream fout("ciclueuler.out");
stack <pair<int,int> > st;
vector <pair<int,int> > v[100050];
int muchii[500050];
int i,a,b,j,n,m,maxi,l,k,lungime;
int main()
{
fin >> n >> m;
for(i = 1; i <= m; i++)
{
fin >> a >> b;
v[a].push_back(make_pair(b,i));
v[b].push_back(make_pair(a,i));
}
st.push(make_pair(1,0));
while(st.size())
{
int ok = 1;
for(;st.top().y < v[st.top().x].size() && ok; st.top().y++)
if(!muchii[v[st.top().x][st.top().y].y])
{
ok = 0;
muchii[v[st.top().x][st.top().y].y] = 1;
a=st.top().x;
st.push(make_pair(v[st.top().x][st.top().y].x,0));
}
if(ok && st.size() > 1)
fout<<a<<" ";
if(ok)
st.pop();
}
return 0;
}