Amazon Interview Question

graph BFS, DFS, disjoint set