What is structure of the graph, is it DAG?
If so I would solve it in following way (lets say that your set of verices is V):
1) change all edges direction so edge (v,w) > (w,v) we get graph G'
2) perform BFS search with all nodes from V in algorithm queue
Explenation: all vertices reachable from set V in graph G' are on some path w1..w2..wn..v so they can be defined as parent of set V.
You can use some quickgraph algorithms to help you. For instance instead of one BFS ( don't know if you can manipulate nodes queue
in different way then way by reflection) you can do one BFS for each v e V and add all vertices with BlackColor to set. After all iterations
your set will contain parent nodes.
I hope it would be helpfull.
Witek
