title: Build Tree from List of "Contains" relationships
body: <p>I have a list of areas (A,B,C...) , each with a list of the towns (1, 2, 3, 4) they contain.  </p>
  
  <p>Note, these are NOT direct parents, the same town shows up in any area that contains it.</p>
  
  <pre><code>A: 1 2 3 4 5 6 7 8 9 
  B: 2 3 4 5
  C: 4 5
  D: 2 3
  E: 5 6 7
  </code></pre>
  
  <p>In my case, they always form a unique hierarchical relationship where an area can contain another area, along with the towns that are not in any of the child areas.</p>
  
  <pre><code>A: B E   1 8 9
  B: C D
  C:       4 5
  D:       2 3
  E:       5 6 7
  </code></pre>
  
  <p>If we assume that the hierarchy is unique, can someone give me a pointer to an algorithm in any general purpose language (or pseudo-code) (I'm using C#) to derive the hierarchy?</p>
  
  <p>I've developed something that I think works, but I'd prefer something that's more mathematically certain than "this seems to work".</p>
  
  <p>I'm perfectly happy to have it break if there is no unique hierarchy.</p>
  
  <p>Many thanks</p>