Graph Algorithms

Answer & solution
Official answer: 60
Approach: DFS starts a new tree exactly when it moves to a previously unvisited connected component. Each resulting tree spans that component.
1. Suppose there are c components and their vertex counts are v1,…,vc. The counts sum to 100.
2. A tree with vi vertices has exactly vi−1 edges. This includes an isolated vertex: vi=1 gives zero edges.
3. Summing over the DFS forest gives 40=Σ(vi−1)=Σvi−c=100−c.
4. Solving yields c=100−40=60.
Answer: 60 connected components. The original graph may have additional nontree edges and cycles; the given 40 counts only forest edges. One can also view each of those 40 tree edges as discovering one nonroot vertex, leaving 60 roots, one for each component.