<p>You are given an integer <code>n</code>, which indicates that there are <code>n</code> courses labeled from <code>1</code> to <code>n</code>. You are also given a 2D integer array <code>relations</code> where <code>relations[j] = [prevCourse<sub>j</sub>, nextCourse<sub>j</sub>]</code> denotes that course <code>prevCourse<sub>j</sub></code> has to be completed <strong>before</strong> course <code>nextCourse<sub>j</sub></code> (prerequisite relationship). Furthermore, you are given a <strong>0-indexed</strong> integer array <code>time</code> where <code>time[i]</code> denotes how many <strong>months</strong> it takes to complete the <code>(i+1)<sup>th</sup></code> course.</p>
<p>You must find the <strong>minimum</strong> number of months needed to complete all the courses following these rules:</p>
<ul>
<li>You may start taking a course at <strong>any time</strong> if the prerequisites are met.</li>
<li><strong>Any number of courses</strong> can be taken at the <strong>same time</strong>.</li>
</ul>
<p>Return <em>the <strong>minimum</strong> number of months needed to complete all the courses</em>.</p>
<p><strong>Note:</strong> The test cases are generated such that it is possible to complete every course (i.e., the graph is a directed acyclic graph).</p>