According to the book (Intro to Algorithm), in dfs, edges are classified as 4 kinds:
- Tree Edge, if in edge (u,v), v is first discovered, then (u, v) is a tree edge.
- Back Edge, if ......, v is discovered already and v is an ancestor, then it's a back edge.
- Forward Edge, if ......, v is discovered already and v is a descendant of u, forward edge it is.
- Cross Edge, all edges except for the above three.
My question is how can I identify whether v is u's ancestor or descendant when I'm trying to figure out if (u, v) is a back or forward edge?