Pagini recente » Cod sursa (job #2785278) | Cod sursa (job #588317) | Cod sursa (job #1218546) | Cod sursa (job #3183864) | Cod sursa (job #2575545)
#include <cstdio>
#include <algorithm>
#include <vector>
using namespace std;
FILE *f = fopen("ciclueuler.in","r");
FILE *g = fopen("ciclueuler.out","w");
int n,m;
vector<pair<int,int> > graph[100005];
bool used[500005];
int main(){
fscanf(f,"%d %d",&n,&m);
for(int i = 1;i <= m;i++){
int x,y;
fscanf(f,"%d %d",&x,&y);
graph[x].push_back({y,i});
graph[y].push_back({x,i});
}
vector<int> v;
v.push_back(1);
while((int)v.size() > 0){
int nod = v.back();
while(graph[nod].empty() == false && used[graph[nod].back().second] == true){
graph[nod].pop_back();
}
if(graph[nod].empty()){
if((int)v.size() > 1){
fprintf(g,"%d ",nod);
}
v.pop_back();
}
else{
used[graph[nod].back().second] = true;
v.push_back(graph[nod].back().first);
}
}
fclose(f);
fclose(g);
return 0;
}