Graph Theory37 sections · 1633 units
Open in Course

Practice Problem 1

(SCC detection)

Practice Problem: Given a directed graph with nn nodes and mm edges, find the number of SCCs. Input format: First line contains nn and mm. Next mm lines contain directed edges uvu \to v. Output: Print the number of SCCs.

Example: Graph 12311 \to 2 \to 3 \to 1, 4544 \to 5 \to 4 has 22 SCCs: {1,2,3}\{1, 2, 3\} and {4,5}\{4, 5\}. Try implementing this yourself using either Kosaraju or Tarjan before looking at the solution.