-
Notifications
You must be signed in to change notification settings - Fork 0
/
1039.cpp
55 lines (48 loc) · 1.01 KB
/
1039.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
53
54
55
#include <iostream>
#include <cstring>
#include <cstdio>
using namespace std;
const int maxn = 30005;
int N;
int idx[1 << 15 + 5];
struct node
{
int lson, rson;
node() : lson(0), rson(0) {}
}arr[maxn];
void preOrder(int now)
{
if (now == -1) return;
idx[arr[now].lson] = idx[now] << 1;
idx[arr[now].rson] = idx[now] << 1 | 1;
preOrder(arr[now].lson);
preOrder(arr[now].rson);
}
void postOrder(int now)
{
if (now == -1) return;
postOrder(arr[now].lson);
postOrder(arr[now].rson);
printf("%d ", now);
}
int main()
{
return 0;
scanf("%d", &N);
int now, ls, rs;
int root = -1;
for (int i = 1; i <= N; ++i)
{
scanf("%d%d%d", &now, &ls, &rs);
if (root == -1) root = now;
arr[now].lson = ls;
arr[now].rson = rs;
}
idx[root] = 1;
preOrder(root);
for (int i = 1; i <= N; ++i)
printf("%d ", idx[i]);
putchar('\n');
postOrder(root);
return 0;
}