How do you import hierarchical data that uses the adjacency list model into Craft Structures or Categories?
This looks like a good high-level description of how to go about it.
Also possibly useful: How do you convert a parent-child (adjacency) table to a nested set using PHP and MySQL?.