Learn
Practice
Newsletter
Resources
Mobile
New
F
Toggle theme
0
F
0
Toggle menu
Animations
← Back to All Animations
Min Cost to Connect All Points
Bookmark
Input
Example 1
Example 2
Square
T-Shape
Custom
points
=
[[0,0],[2,2],[3,10],[5,2],[7,0]]
Points & MST Edges
P0
(0,0)
P1
(2,2)
P2
(3,10)
P3
(5,2)
P4
(7,0)
Union-Find Parent Array:
Cost: 0
Legend:
Default
Considering
In MST
Rejected (Cycle)
Points & MST Edges
P0
(0,0)
P1
(2,2)
P2
(3,10)
P3
(5,2)
P4
(7,0)
Union-Find Parent Array:
Cost: 0
Legend:
Default
Considering
In MST
Rejected (Cycle)
Points & MST Edges
3
P0
(0,0)
P1
(2,2)
P2
(3,10)
P3
(5,2)
P4
(7,0)
Union-Find Parent Array:
0
P0
1
P1
2
P2
3
P3
4
P4
Cost: 0
Legend:
Default
Considering
In MST
Rejected (Cycle)
Points & MST Edges
3
P0
(0,0)
P1
(2,2)
P2
(3,10)
P3
(5,2)
P4
(7,0)
Union-Find Parent Array:
0
P0
1
P1
2
P2
1
P3
4
P4
Cost: 3
Legend:
Default
Considering
In MST
Rejected (Cycle)
Points & MST Edges
3
4
P0
(0,0)
P1
(2,2)
P2
(3,10)
P3
(5,2)
P4
(7,0)
Union-Find Parent Array:
1
P0
1
P1
2
P2
1
P3
4
P4
Cost: 7
Legend:
Default
Considering
In MST
Rejected (Cycle)
Points & MST Edges
3
4
4
P0
(0,0)
P1
(2,2)
P2
(3,10)
P3
(5,2)
P4
(7,0)
Union-Find Parent Array:
1
P0
1
P1
2
P2
1
P3
1
P4
Cost: 11
Legend:
Default
Considering
In MST
Rejected (Cycle)
Points & MST Edges
3
4
4
7
P0
(0,0)
P1
(2,2)
P2
(3,10)
P3
(5,2)
P4
(7,0)
Union-Find Parent Array:
1
P0
1
P1
2
P2
1
P3
1
P4
Cost: 11
Legend:
Default
Considering
In MST
Rejected (Cycle)
Points & MST Edges
3
4
4
7
P0
(0,0)
P1
(2,2)
P2
(3,10)
P3
(5,2)
P4
(7,0)
Union-Find Parent Array:
1
P0
1
P1
2
P2
1
P3
1
P4
Cost: 11
Legend:
Default
Considering
In MST
Rejected (Cycle)
Points & MST Edges
3
4
4
7
P0
(0,0)
P1
(2,2)
P2
(3,10)
P3
(5,2)
P4
(7,0)
Union-Find Parent Array:
1
P0
1
P1
2
P2
1
P3
1
P4
Cost: 11
Legend:
Default
Considering
In MST
Rejected (Cycle)
Points & MST Edges
3
4
4
9
P0
(0,0)
P1
(2,2)
P2
(3,10)
P3
(5,2)
P4
(7,0)
Union-Find Parent Array:
1
P0
1
P1
2
P2
1
P3
1
P4
Cost: 11
Legend:
Default
Considering
In MST
Rejected (Cycle)
Points & MST Edges
3
4
4
9
P0
(0,0)
P1
(2,2)
P2
(3,10)
P3
(5,2)
P4
(7,0)
Union-Find Parent Array:
1
P0
1
P1
1
P2
1
P3
1
P4
Cost: 20
Legend:
Default
Considering
In MST
Rejected (Cycle)
algo
master
.
io
Step:
Initialize 5 points, 10 possible edges (sorted by cost)
0 / 24
Input
Example 1
Example 2
Square
T-Shape
Custom
points
=
[[0,0],[2,2],[3,10],[5,2],[7,0]]
0 / 24
algo
master
.
io
Step:
Initialize 5 points, 10 possible edges (sorted by cost)