431. Find the Connected Component in the Undirected Graph
Find the number connected component in the undirected graph. Each node in the graph contains a label and a list of its neighbors. (a connected component (or just component) of an undirected graph is a subgraph in which any two vertices are connected to each other by paths, and which is connected to no additional vertices in the supergraph.)
Notice
Each connected component should sort by label.
Example
Given graph:123456A------B C \ | | \ | | \ | | \ | | D E
Return {A,B,D}
, {C,E}
. Since there are two connected component which is {A,B,D}
, {C,E}
Union Find
先做的lintcode 432, 这两个题目的Union Find解法基本一样。
|
|