title: Splitting a Directed Acyclic Graph (DAG) into components, then finding root and last child in those components
body: <p>I want to split a graph into its components (like in the example DAG below. Note the colored identifiers of each node as they represent the components). After I've found the components in the picture I want to find the root and last child of that component. Take the <strong>blue</strong> component for example, the root is <code>E</code> and the last child is <code>H</code>. <strong>Green</strong>: root <code>B</code> - last child <code>H</code>.</p>
  
  <p>Example graph:
  <img src="https://i.imgur.com/ZYJN0vI.png" alt="Example Graph"></p>
  
  <p>If you can find a connection between <code>E</code>-<code>H</code>, <code>B</code>- <code>E</code>, <code>B</code>-<code>H</code>, <code>A</code>-<code>I</code> without splitting it into components. Let me know, as that is my final goal.</p>
  
  <p>About the compiling of components. That is actually my final goal. I just wanted to include that to maybe get you a better understanding of what I'm trying to achieve. This can be don't once I find these connections.</p>
  
  <p>Questions I found helpful but not answered my question: </p>
  
  <ul>
  <li><p><a href="https://stackoverflow.com/questions/14865081/algorithm-to-find-lowest-common-ancestor-in-directed-acyclic-graph">Algorithm to find lowest common ancestor in directed acyclic graph?</a> </p></li>
  <li><p><a href="https://stackoverflow.com/questions/6116740/finding-best-common-ancestor-of-two-leaf-nodes-where-nodes-have-zero-one-or-tw">Finding best common ancestor of two leaf nodes where nodes have zero, one, or two parents</a></p></li>
  </ul>
  
  <p>(These answers might be sufficient but I don't know how to implement it)</p>
  
  <p>Note:</p>
  
  <ul>
  <li><p>Please post all example code in C++ or C# (if you're going to post example code)</p></li>
  <li><p>This is my first question. If I've done something wrong please let me know.</p></li>
  </ul>
  
  <p>// Big edit:
  Reworked the question to make it more clear what I want. Introduced components as I might think that will be more helpful.</p>