-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy patheuler tours.cpp
More file actions
54 lines (42 loc) · 706 Bytes
/
euler tours.cpp
File metadata and controls
54 lines (42 loc) · 706 Bytes
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
#include<bits/stdc++.h>
using namespace std;
const int N = 1e5;
vector<int> gr[N];
void dfs1(int cur, int par) {
// time in
cout << cur << " ";
for (auto x : gr[cur]) {
if (x != par) {
// x is child node
dfs1(x, cur);
}
}
// time out
cout << cur << " ";
}
void dfs2(int cur, int par) {
cout << cur << " ";
for (auto x : gr[cur]) {
if (x != par) {
// x is child node
dfs2(x, cur);
cout << cur << " ";
}
}
}
int main()
{
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
int n;
cin >> n;
for (int i = 0; i < n - 1; i++) {
int x, y;
cin >> x >> y;
gr[x].push_back(y);
gr[y].push_back(x);
}
// dfs1(1, 0);
dfs2(1, 0);
return 0;
}