Pagini recente » Cod sursa (job #439493) | Cod sursa (job #439549) | Cod sursa (job #586855) | Cod sursa (job #644178) | Cod sursa (job #2095543)
#include <cstdio>
#include <set>
#include <vector>
#include <algorithm>
using namespace std;
FILE *f = fopen("ciclueuler.in","r");
FILE *g = fopen("ciclueuler.out","w");
int N,M;
vector<pair<int,int> > G[100005];
bool U[500005];
int st[500005];
int len;
int main()
{
fscanf(f,"%d %d",&N,&M);
for(int i = 1;i <= M;i++){
int x,y;
fscanf(f,"%d %d",&x,&y);
G[x].push_back({y,i});
G[y].push_back({x,i});
}
st[++len] = 1;
while(len){
int nod = st[len];
while(!G[nod].empty() && U[G[nod].back().second]){
G[nod].pop_back();
}
if(!G[nod].empty()){
int v = G[nod].back().first;
U[G[nod].back().second] = 1;
G[nod].pop_back();
st[++len] = v;
}
else{
if(len != 1){
fprintf(g,"%d ",nod);
}
len--;
}
}
fclose(f);
fclose(g);
return 0;
}