Pagini recente » Cod sursa (job #1759140) | Cod sursa (job #246930) | Cod sursa (job #213859) | Cod sursa (job #543667) | Cod sursa (job #992729)
Cod sursa(job #992729)
#include <cstdio>
#include <vector>
using namespace std;
const int Nmax = 100005;
const int Mmax = 500005;
#define st first
#define dr second
#define pb push_back
#define mp make_pair
#define FOR(i,a,b) for(int (i) = (a) ; i <= (b) ; ++i)
pair<int,int> vertex[Mmax];
vector<int>answer,lvrtx[Nmax];
bool used[Mmax];
int N,M;
void DFS(int k){
for(vector<int>::iterator it = lvrtx[k].begin(); it != lvrtx[k].end(); ++it)
if(!used[*it]){ // marchez muchia ca folosita
used[*it]=1;
DFS(vertex[*it].st+vertex[*it].dr-k);
}
answer.push_back(k);// cand ma intorc notez din ce nod vin
}
int main()
{
freopen("ciclueuler.in", "r", stdin);
freopen("ciclueuler.out", "w", stdout);
scanf("%d %d",&N,&M);
int x,y;
FOR(i,1,M){
scanf("%d %d",&x,&y);
vertex[i]=mp(x,y); // imi salvez muchiile
lvrtx[x].pb(i); // imi notez ce muchie pot folosi din nodul x respectiv y
lvrtx[y].pb(i);
}
DFS(1);
FOR(i,0,answer.size()-1)
printf("%d ",answer[i]);
return 0;
}