Algorithm to Group Vertices of Graph
this seems to be known as the "Lowest Common Ancestor" problem of graphs. see eg


Faster algorithms for ﬁnding lowest common ancestors
in directed acyclic graphs Czumaj et al
LCA Queries in Directed Acyclic Graphs Kowaluk, Lingas 
Lowest Common Ancestors in Trees and Directed Acyclic Graphs Bender et al
algorithm to find LCA in DAG, so.se