Finding maximum path of a complex array
<p>I have an array:</p>

<pre><code>$data = array(
  1 =&gt; array(
    "time" =&gt; 1,
    "parent" =&gt; array(4)
  ),
  2 =&gt; array(
    "time" =&gt; 3,
    "parent" =&gt; array(4, 5)
  ),
  3 =&gt; array(
    "time" =&gt; 2,
    "parent" =&gt; array(6)
  ),
  4 =&gt; array(
    "time" =&gt; 1,
    "parent" =&gt; array(6)
  ),
  5 =&gt; array(
    "time" =&gt; 1,
    "parent" =&gt; array(4)
  ),
  6 =&gt; array(
    "time" =&gt; 1,
    "parent" =&gt; array()
  )
);
</code></pre>

<p>Key is the ID of an element, parent is an array of elements, which refers to element id and time is just an integer.</p>

<p>This is an illustrated example of a given array:</p>

<p><a href="http://i.stack.imgur.com/k06xu.png" rel="nofollow">Schema</a></p>

<p>The integer on the bottom-left is the "id" and the integer in the middle is "time".</p>

<p>My goal here is find the most time-consuming path of this array. In the given example, the path would be 2->5->4->6 (id wise) resulting in 6 "time" overall. It looks pretty easy on paper, however I can't really seem to code an algorythm to get the elements of the most time-consuming path. I would appreciate any kind of help.</p>

<p>I think the algorythm should be kind of bruteforce-ish and check through all of the options available. Thus with the given array it would go like:</p>

<pre><code>1 -&gt; 4 -&gt; 6 = 3
2 -&gt; 4 -&gt; 6 = 5
2 -&gt; 5 -&gt; 4 -&gt; 6 = 6 
3 -&gt; 6 = 3
4 -&gt; 6 = 2
5 -&gt; 4 -&gt; 6 = 3
</code></pre>

<p>Thanks in advance.</p>
