title: resolve a tree knowing ALL parents and ancestors of leaf nodes
body: <p>It is pretty straighforward to build a tree if you know the immediate parent of all nodes. But what if you have information about ALL parents of the leaf nodes (including grand-parents, great-grand-parent, etc.) without knowing if it is immediate parent or not?</p>
  
  <p>For example consider the following tree:</p>
  
  <pre><code>              A -----&gt;  B ------&gt; C -----&gt; G
  
                         |
  
                         D ------&gt; E
  
                         |
  
                         F
  </code></pre>
  
  <p>The information available to describe this tree is the following CSV file:</p>
  
  <p>child, parent</p>
  
  <p>E,D</p>
  
  <p>E,B</p>
  
  <p>E,A</p>
  
  <p>F,D</p>
  
  <p>F,B</p>
  
  <p>G,C</p>
  
  <p>G,B</p>
  
  <p>G,A</p>
  
  <p>F,A</p>
  
  <p>Could you please give some advice on a general algortihm to solve this?</p>