You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: solutions/1-1000/684-redundant-connection.md
+6-4Lines changed: 6 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -32,7 +32,9 @@ Output: [1,4]
32
32
- The given graph is connected.
33
33
34
34
## Intuition
35
-
- This undirected graph has only **one****connected component**, which is a tree.
35
+
- In graph theory, a tree is an _undirected graph_ in which any two vertices are connected by exactly one path, or equivalently a **connected acyclic undirected graph**. Like this:
36
+

37
+
36
38
- When an edge is added to the graph, its two nodes are also added to the graph.
37
39
- If the two nodes are already in the graph, then they must be on the same tree. At this time, a cycle is bound to be formed.
38
40
@@ -44,9 +46,9 @@ Output: [1,4]
44
46
45
47
### 'UnionFind' algorithm
46
48
-`UnionFind` algorithm typically has three methods:
47
-
- The `unite(node1, node2)` operation can be used to merge two trees.
48
-
- The `find_root(node)` method can be used to return the root of a node.
49
-
- The `same_root(node1, node2)` method can be used to judge if two nodes are in the same tree.
49
+
- The `unite(node1, node2)` operation is used to merge two trees.
50
+
- The `find_root(node)` method is used to return the root of a node.
51
+
- The `same_root(node1, node2)` method is used to determine whether two nodes are in the same tree.
0 commit comments