-
Notifications
You must be signed in to change notification settings - Fork 2.8k
/
EulerTour.cpp
54 lines (46 loc) · 1.08 KB
/
EulerTour.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/*************************************************************************
> File Name: EulerTour.cpp
> Author: Louis1992
> Mail: [email protected]
> Blog: http://gzc.github.io
> Created Time: Thu Jul 16 13:54:43 2015
************************************************************************/
#include <iostream>
#include <vector>
using namespace std;
#define MAX_VERTEX 10005
typedef struct {
int end_vertex;
int visited;
} Edge;
int Nvertex;
int Nedge;
vector<Edge> vertex[MAX_VERTEX];
static void input() {
int i, u, v;
Edge tmp;
tmp.visited = 0;
cin >> Nvertex >> Nedge;
for (i = 0; i < Nedge; ++i) {
cin >> u >> v;
tmp.end_vertex = u;
vertex[v].push_back(tmp);
tmp.end_vertex = v;
vertex[u].push_back(tmp);
}
}
static void euler(int x) {
int i;
for (i = vertex[x].size() - 1; i >= 0; --i) {
if (!vertex[x][i].visited) {
vertex[x][i].visited = 1;
euler(vertex[x][i].end_vertex);
}
}
cout << x << endl;
}
int main() {
input();
euler(1);
return 0;
}