-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheulerpath.cpp
More file actions
81 lines (72 loc) · 1.29 KB
/
eulerpath.cpp
File metadata and controls
81 lines (72 loc) · 1.29 KB
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#include <fstream>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
using namespace std;
#define MAX 505
int conn[MAX][MAX];
int deg[MAX];
int pos=0;
int path[2000];
void find_circuit(int x) {
if(!deg[x]) {
path[pos++]=x;
} else {
while(1) {
if(!deg[x]) break;
for (int y=0; y<MAX; y++) {
if(conn[x][y]) {
deg[x]--; deg[y]--;
conn[x][y]--; conn[y][x]--;
find_circuit(y);
}
}
}
path[pos++]=x;
}
}
int main() {
for (int i=0; i<MAX; i++) {
deg[i]=0;
for (int j=0; j<MAX; j++)
conn[i][j]=0;
}
int m; cin>>m;
for (int i=0; i<m; i++) {
int x,y; fin>>x>>y;
deg[x]++; deg[y]++;
conn[x][y]++; conn[y][x]++;
}
int cur=-1;
for (int i=0; i<MAX; i++)
if(deg[i]%2) { cur=i; break; }
if(cur==-1) {
for (int i=0; i<MAX; i++)
if(deg[i]) { cur=i; break; }
}
find_circuit(cur);
for (int i=0; i<pos; i++) cout << path[pos-1-i] << endl;
return 0;
}