Pagini recente » Cod sursa (job #2154025) | Cod sursa (job #735620) | Cod sursa (job #735639) | Cod sursa (job #1866170) | Cod sursa (job #2443091)
#include <fstream>
#include <cstring>
#include <vector>
std::ifstream cin("ciclueuler.in");
std::ofstream cout("ciclueuler.out");
using namespace std;
#define maxn 500505
vector<int> G[maxn];
bool used_edge[maxn];
int from[maxn],to[maxn], N,M;
void citire(){
int x,y;
cin>>N>>M;
for(int i=1;i<=M;i++){
cin>>x>>y;
G[x].push_back(i);
G[y].push_back(i);
from[i]=x;
to[i]=y;
}
}
int main()
{
int node;
citire();
for(int i=1;i<=N;i++)
if(G[i].size()&1){
cout<<"-1\n";
return 0;
}
vector<int> ans,stk;
stk.push_back(1);
while(!stk.empty()){
node=stk.back();
if(!G[node].empty()){
int e=G[node].back();
G[node].pop_back();
if(!used_edge[e]){
used_edge[e]=true;
int to=from[e] ^ ::to[e] ^ node;//:: operator is for accesing an global variable when there is a local variable with the same name
stk.push_back(to);
}
}else{
stk.pop_back();
ans.push_back(node);
}
}
for(vector<int>::iterator it=ans.begin();it!=ans.end()-1;it++)
cout<<*it<<' ';
return 0;
}
*/