Pagini recente » Cod sursa (job #461498) | Cod sursa (job #2059413) | Cod sursa (job #553492) | Cod sursa (job #2630840) | Cod sursa (job #1017784)
#include <cstdio>
#include <vector>
using namespace std;
const int N = 100000, M = N * 5;
struct listNode
{
int vertex;
listNode * nextListNode;
};
struct list
{
listNode * firstNode;
listNode * lastNode;
};
struct muchie
{
int a, b;
bool used;
};
vector <vecini *> vecini [N + 1];
int n, m, sol;
bool cE = true;
void init ()
{
int a, b, i;
freopen ("ciclueuler.in", "r", stdin);
freopen ("ciclueuler.out", "w", stdout);
scanf ("%d %d", &n, &m);
for (i = 0; i < m; i ++)
{
scanf ("%d %d", &a, &b);
Muchie * edge = new Muchie ();
edge -> a = a;
edge -> b = b;
edge -> used = false;
vecini [a].push_back (& edge);
vecini [b].push_back (& edge);
}
}
list DFS (int vertex)
{
list answer;
int nextVertex = vecini [vertex][vecini[vertex].size () - 1];
vecini [vertex]. pop_back ();
listNode *firstNod = new listNode ();
node -> vertex = vertex;
node -> nextListNode = NULL;
int currentVertex = nextVertex;
listNode *previosNode = firstNode;
while (vecini [currentVertex]. size () > 0)
{
previousNode -> nextListNode = new ListNode ();
previousNode = previousNode -> nextListNode;
previousNode -> vertex = currentVertex;
previousNode -> nextListNode = NULL;
int previousVertex = currentVertex;
currentVertex = vecini [currentVertex] [vecini[vertex].size () - 1];
vecini [previousVertex]. pop_back ();
}
answer. firstNode = firstNode;
answer. lastNode = previousNode;
return answer;
}
void solve ()
{
int i;
for (i = 1; i <= n; i ++)
if (vecini [i].size () % 2 == 1)
cE = false;
if (cE)
DFS (1);
}
void afis ()
{
if (cE)
printf ("%d ", sol);
else
printf ("-1");
}
int main ()
{
init ();
solve ();
afis ();
return 0;
}