#include <iostream>
#include <fstream>

using namespace std;

int tree[114514][2]; 
int root;         
int nodeCount;    

void input() {
    ifstream inFile("dfs.in");
    inFile >> nodeCount; 
    for (int i = 0; i < 109; i++) {
        tree[i][0] = -1; 
        tree[i][1] = -1; 
    }
    for (int i = 1; i <= nodeCount; i++) {
        int parent, leftChild, rightChild;
        inFile >> parent >> leftChild >> rightChild;
        tree[parent][0] = leftChild;   
        tree[parent][1] = rightChild;  
    }
    inFile.close();
}

void dfs(int curNode) {
    cout << curNode << " "; 
    if (tree[curNode][0] != -1) { 
        dfs(tree[curNode][0]); 
    }
    if (tree[curNode][1] != -1) { 
        dfs(tree[curNode][1]); 
    }
}


int main() {
    input(); 
    root = 1; 
    dfs(root); 
    return 0;
}
