Observe the longest path starts at some vertex and ends at some vertex.
If for each vertex i,
we know the length, L[i],
of the longest path that starts
at this vertex, we can compute the length of the longest path in the graph
by computing the maximum of the L[i]s.
For L[i], we obtain the following recurrence
L[i] = 0 if S(i) is empty;
otherwise L[i] is
max{length[i][j] + L[j] | j is in S(i)}.
Using this recurrence and the fact that the graph is acyclic and
the vertices are numbered as stated, we arrive at the following algorithm:
MaxLength = 0;
for (int i = n; i > 0; i--) {
L[i] = 0;
for (each vertex j in S(i))
L[i] = max(L[i], length[i][j] + L[j]);
MaxLength = max(MaxLength, L[i]);
}