Pagini recente » Cod sursa (job #2429732) | Cod sursa (job #2407114) | Cod sursa (job #2945770) | Cod sursa (job #1491251) | Cod sursa (job #1090767)
#include <fstream>
#include <stdlib.h>
using namespace std;
#define DEBUG false
#define MAXN 100001
#define MAXM 500000
#if DEBUG
#include <iostream>
#define INFILE "/Users/biordach/Documents/Xcode Projects/training/training/ciclueuler.in"
#define __OUT cout
#else
#define INFILE "ciclueuler.in"
#define OUTFILE "ciclueuler.out"
ofstream __OUT(OUTFILE);
#endif
struct node {
int dest;
node *next, *correspondent;
}*first[MAXN], *last[MAXN];
int grades[MAXN];
int n, m;
void readInput();
void solve();
void printOutput();
int main(int argc, const char * argv[])
{
readInput();
solve();
printOutput();
#if DEBUG == false
__OUT.close();
#endif
return 0;
}
void readInput(){
ifstream in(INFILE);
in>>n>>m;
for(int i=0; i < m; i++){
int x, y;
in >>x >> y;
node *q = new node;
node *w = new node;
q->next = NULL;
w->next = NULL;
q->correspondent = w;
w->correspondent = q;
q->dest = y;
w->dest = x;
if(!first[x]) {
first[x] = last[x] =q;
} else {
last[x] -> next = q;
last[x] = q;
}
if(!first[y]) {
first[y] = last[y] = w;
} else {
last[y] -> next = w;
last[y] = w;
}
grades[x] ++;
grades[y] ++;
}
in.close();
}
void solve(){
for (int i = 0; i <= n; i++)
if(grades[i] % 2){
__OUT<<-1<<'\n';
return;
}
int current = 1;
node* q = first[current];
while (q) {
__OUT<<current<<' ';
while (q && !q->dest)
q = q->next;
if(!q)
continue;
node *w = q->correspondent;
current = q->dest;
q->dest = w->dest = 0;
q = w;
}
}
void printOutput(){
}