Given is the following graph which is logically divided into layers (with Dijkstra's shortest paths algorithm):
Vertices Layer Root 0 / \ A B 1 / \ | C D E 2 \ | / \ | / F 3
Now I'm looking for an algorithm which groups vertices when they have a (single) common ancestor in the previous layer, e.g. for the graph in the example the groups would be:
0: A, B 1: C, D 2: E 3: F
I know that this is doable by visiting vertices and comparing ancestors but I was wondering whether there is a well known algorithm for it.
Update: My question is really only related to find groups. I'm aware of the fact, that I can traverse vertices and test for incoming edges and group those vertices. Furthermore, the graph is fully constructed.
One (now deleted) answer mentioned DFS, which creates a search forest (as BFS creates a search tree which I basically used for levels, though I mentioned Dijkstra). So, I assume that combining BFS and DFS could give me the desired result.