# Include <iostream> # include <cstdio> # include <cstring> # include <cmath> # include <algorithm> # include <bitset> # include <iomanip> using namespace std; int a [20] [3]; void work1 (int x) //////////////////////////////////////// //// traverse {printf ("% d ", x); if (a [x] [1]! = 0) work1 (a [x] [1]); if (a [x] [2]! = 0) work1 (a [x] [2]);} void work2 (int x) //////////////////////////////////////// //// traverse in the middle order {if (a [x] [1]! = 0) work2 (a [x] [1]); printf ("% d", x); if (a [x] [2]! = 0) work2 (a [x] [2]);} void work3 (int x) //////////////////////////////////////// //// subsequent traversal {if (a [x] [1]! = 0) work3 (a [x] [1]); if (a [x] [2]! = 0) work3 (a [x] [2]); printf ("% d", x);} int main () {int n; while (scanf ("% d", & n )! = EOF) {for (int I = 1; I <= n; ++ I) scanf ("% d", & a [I] [1], & a [I] [2]); work1 (1); cout <endl; work2 (1); cout <endl; work3 (1 ); cout <endl;} return 0 ;}