Given an directed Graph $G(V,E)$ and a source node $v \in V$. I need to find a partition for $G$ into two sets $X$ and $Y$ in such way that the nodes in $X$ are those that there is a path from $v$ to each of them, and the nodes $Y$ are those that there is no path.
Now, I can use a Depth-first search with $v$ as source node and put the result nodes into $X$ and the other nodes into $Y$ and connect the two sets with the remaining edges. But I want to know if there is an optimal algorithm if exists to do that. (Sorry, I am new into Graph Theory).