find a cycle in a directed/ undirected graph Directed Graph: DFS 3 kinds of nodes:
black: already explored, no cycle
grey: under exploration, on one path
white: not explored
turn grey to black: all of its children has visited, and there is no cycle
if the node next to visit is grey: found a cycle
if the node next to visit is black: no need to visit, since all of its children has been explored, and no cycle found(all black)
topological sort
Union Find
Undirected graph: 2 kinds of nodes black and white(don’t need grey) like directed graph topological sort 求图中所有点的度 删除度<=1的node,和相邻的边, 重复2直到无未删除的点 如果存在未删除的点,则有环,否则无环