Problem
Figure 1. The graph from the dataset
图1 。数据集中的图形
The task is to use depth-first search to compute the number of connected components in a given undirected graph.
Given: A simple graph with vertices in the edge list format.
Return: The number of connected components in the graph.
See Figure 1 for visual example from the sample dataset.
返回值:图形中连接的组件数。
有关示例数据集中的可视示例,请参见图1。
Sample Dataset
12 13 1 2 1 5 5 9 5 10 9 10 3 4 3 7 3 8 4 8 7 11 8 11 11 12 8 12
Sample Output
3