I'm not sure I understand what you're looking for. Could you provide some more examples to clarify?
One interpretation is that you want to tag the source vertices in a graph (those with zero indegree) and find for each vertex the set of sources that lead to that vertex. For vertices 1-8 in the graph, this would give you [{1}, {1}, {1}, {1}, {1, 6}, {7}, {7}]. Ankur <http://www.ankurdave.com/>